๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐Ÿฆ• ๊ณต๋ฃก์ด ๋˜์ž!

2BPerfect...11 ๋ณธ๋ฌธ

Development/Python

2BPerfect...11

Kirok Kim 2022. 1. 26. 16:17
๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”1
#matplotlib

import matplotlib.pyplot as plt

%matplotlib qt #ํŒ์—…์ฐฝ์—์„œ ๊ทธ๋ž˜ํ”„๋ฅผ ์ถœ๋ ฅํ• ๋•Œ
%matplotlib inline # ๊ฒฐ๊ณผ๋ถ€๋ถ„ ์ถœ๋ ฅ

# ์„  ๊ทธ๋ž˜ํ”„
๊ธฐ๋ณธ์ ์ธ ์„  ๊ทธ๋ž˜ํ”„ ๊ทธ๋ฆฌ๊ธฐ
plt.plot([x,]y[,fmt])

plt.plot(y)
plt.plot(y,fmt)
plt.plot(x,y)
plt.plot(x,y,fmt)

data1=[1,2,3,4,5]

plt.plot(data1)
plt.show()

์˜ˆ์‹œ
import numpy as np

x=np.arange(-4.5,5,0.5)
y=2*x**2

# ์—ฌ๋Ÿฌ ๊ทธ๋ž˜ํ”„ ๊ทธ๋ฆฌ๊ธฐ

y2=5*x+30
y3=4*x**2+10

plt.plot(x1,y1,x2,y2~~)

plt.plot(x,y)
plt.plot(x,y2)
plt.plot(x,y3)
plt.show()
plt.figure()# ์ƒˆ๋กญ๊ฒŒ ์ƒ์„ฑ๋œ ๊ทธ๋ž˜ํ”„ ์ฐฝ์— ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆผ
plt.plot(x,y2)
plt.show() ๋”ฐ๋กœ๋”ฐ๋กœ ๊ทธ๋ ค์ง

plt.figure(n) ์ง€์ •๋œ ๋ฒˆํ˜ธ๋กœ ๊ทธ๋ž˜ํ”„ ์ฐฝ์ด ์ง€์ •๋จ
# %matplotlib inline์˜ ๊ฒฝ์šฐ์—๋Š” ๋ฒˆํ˜ธ๊ฐ€ ๋ช…์‹œ์ ์œผ๋กœ ์ ํ˜€์ ธ ์žˆ์ง€ ์•Š์ง€๋งŒ
# %matplotlib qt๋Š” ์ œ๋ชฉ์— figure๋ฒˆํ˜ธ๊ฐ€ ํ‘œ์‹œ๋จ

๊ทธ๋ž˜ํ”„๋ฅผ ๋ชจ๋‘ ์ง€์šฐ๋ ค๋ฉด clf()
ํ˜„์žฌ ๊ทธ๋ž˜ํ”„ ์ฐฝ์„ ๋‹ซ์œผ๋ ค๋ฉด close()

x= np.arange(-5,5,0.1)
y1=x**2-2
y2=20*np.cos(x)**2

plt.figure(1)
plt.plot(x,y1)

plt.figure(2)
plt.plot(x,y2)

plt.figure(1)
plt.plot(x,y2)

plt.figure(2)
plt.clf() # 2๋ฒˆ ๊ทธ๋ž˜ํ”„๋ฅผ ์ง€์›€
plt.plot(x,y1)

plt.show()

plt.subplot(m,n,p)

m*nํ–‰๋ ฌ๋กœ ์ด๋ค„์ง„ ํ•˜์œ„ ๊ทธ๋ž˜ํ”„ ์ค‘์—์„œ p๋ฒˆ ์œ„์น˜์— ๊ทธ๋ž˜ํ”„๊ฐ€ ๊ทธ๋ ค์ง€๋„๋ก ์ง€์ •
p๋Š” ์™ผ์ชฝ์—์„œ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๊ทธ๋ฆฌ๊ณ  ์œ„์—์„œ ์•„๋ž˜๋กœ ํ–‰๋ ฌ์˜ ์œ„์น˜๋ฅผ ์ง€์ •

211    221 222    321 322
212    223 224    323 324
                  325 326

plt.subplot(2,2,1)
plt.plot(x,y1)

plt.subplot(2,2,2)
plt.plot(x,y2)

plt.subplot(2,2,3)
plt.plot(x,y3)

plt.show()

# ๊ทธ๋ž˜ํ”„์˜ ์ถœ๋ ฅ ๋ฒ”์œ„ ์ง€์ •ํ•˜๊ธฐ
plt.xlim(xmin,xmax)
plt.ylim(ymin,ymax)

[xmin,xmax]=plt.xlim()
[ymin,ymax]=plt.ylim()

plt.plot(x,y1,x,y2)
plt.xlim(-1,1)
plt.ylim(-3,3)๋ฒ”์œ„ ์ง€์ •ํ•ด์„œ ํ™•๋Œ€ํ•ด์„œ ๋ด„

#๊ทธ๋ž˜ํ”„ ๊พธ๋ฏธ๊ธฐ
fmt='[color][line_style][marker]'

์ƒ‰
b ํŒŒ๋ž€์ƒ‰
g ๋…น์ƒ‰
r ๋นจ๊ฐ•
c ์ฒญ๋…น
m ์žํ™
y ๋…ธ๋ž‘
k ๊ฒ€์€์ƒ‰
w ํฐ์ƒ‰

์Šคํƒ€์ผ
-  ์‹ค์„ 
-- ํŒŒ์„ 
:  ์ ์„ 
-. ํŒŒ์„  ์ ์„  ํ˜ผํ•ฉ์„ 

๋งˆ์ปค
o       ์›
^,v,<,> ์‚ผ๊ฐ,์•„๋ž˜,์™ผ,์˜ค๋ฅธ
s       ์‚ฌ๊ฐ
p       ์˜ค๊ฐ
h,H     ์œก๊ฐ1,2
*       ๋ณ„
+       ๋”ํ•˜๊ธฐ
x,X     x,์ฑ„์›Œ์ง„X
D,d     ๋‹ค์ด์•„๋ชฌ๋“œ, ์–‡์€ ๋‹ค์ด์•„๋ชฌ๋“œ

plt.plot(x,y1,'>--r')
plt.show()

๋ฐ˜์‘ํ˜•

'Development > Python' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

2BPerfect...13  (0) 2022.01.27
2BPerfect...12  (0) 2022.01.27
2BPerfect...10  (0) 2022.01.26
2BPerfect...9  (0) 2022.01.25
2BPerfect...8  (0) 2022.01.25
Comments