matplotlib
matplotlib
: ๋ฐ์ดํฐ๋ฅผ ์ฐจํธ(chart)๋ ํ๋กฏ(plot)์ผ๋ก ์๊ฐํ(visulaization)ํ๋ ํจํค์ง ๋ฐ์ดํฐ ๋ถ์์์ Matplotlib์ ๋ฐ์ดํฐ ๋ถ์ ์ด์ ์ ๋ฐ์ดํฐ ์ดํด๋ฅผ ์ํ ์๊ฐํ๋, ๋ฐ์ดํฐ ๋ถ์ ํ์ ๊ฒฐ๊ณผ๋ฅผ ์๊ฐํํ๊ธฐ ์ํด์ ์ฌ์ฉ
pip install matplotlib
๋จ์ํ ๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐ
: ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ธฐ ์ํด์๋ matplotlib์ pyplot
import numpy as np
import matplotlib.pyplot as plt
# ๋ฐ์ดํฐ ์ค๋น
x = np.arange(0, 6, 0.1) # 0์์ 6๊น์ง 0.1 ๊ฐ๊ฒฉ์ผ๋ก ์์ฑ
y = np.sin(x)
# ๊ทธ๋ํ
plt.plot(x, y)
plt.show()

pyplot์ด ๊ธฐ๋ฅ
: ์ ๋ชฉ๊ณผ ๊ฐ ์ถ์ ์ด๋ฆ(๋ ์ด๋ธ) ํ์ ๋ฑ์ ์ฌ์ฉํ ์ ์๋ค
import numpy as np
import matplotlib.pyplot as plt
# ๋ฐ์ดํฐ ์ค๋น
x = np.arange(0, 6, 0.1) # 0์์ 6๊น์ง 0.1 ๊ฐ๊ฒฉ์ผ๋ก ์์ฑ
y1 = np.sin(x)
y2 = np.cos(x)
# ๊ทธ๋ํ
plt.plot(x, y1, label = "sin")
plt.plot(x, y2, linestyle="--", label = "cos") # cos๋ ์ ์ ์ผ๋ก ๊ทธ๋ฆฌ๊ธฐ
plt.xlabel("x")
plt.ylabel("y")
plt.title("sin & cos")
plt.legend() #๋ฒ๋ก ์ฝ์
plt.show()

์ด๋ฏธ์ง ํ์ํ๊ธฐ
: pyplot์๋ ์ด๋ฏธ์ง๋ฅผ ํ์ํด์ฃผ๋ ๋ฉ์๋์ธ imshow()๋ ์๋ค. ์ด๋ฏธ์ง๋ฅผ ์ฝ์ด ๋ค์ผ ๋๋ matplotlib.image๋ชจ๋์ imread()๋ฉ์๋๋ฅผ ์ด์ฉ
import matplotlib.pyplot as plt
from matplotlib.image import imread
img = imread('xxx.png') # ์ด๋ฏธ์ง ์ฝ์ด์ค๊ธฐ(์ ๋นํ ๊ฒฝ๋ก๋ฅผ ์ค์ ํด์ผ ํ๋ค)
plt.imshow(img)
plt.show()
Last updated
Was this helpful?