0Install
pip install matplotlib
Import
import matplotlib.pyplot as plt
* ๋ฒ์ ํ์ธ
import matplotlib
print(matplotlib.__version__)
plot image
#load image
import cv2
img = cv2.imread('dog.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
#show iage
plt.imshow(img)
figure ํฌ๊ธฐ ์กฐ์
plt.figure(figsize=(15, 15))
plt.imshow(img)
colorbar ํ์
plt.imshow(img[...,0]) #๋ง์ง๋ง ์ฑ๋๋ง ํ์
plt.colorbar()
* Colorbar ์์น ์ด๋ (ver 3.4๋ถํฐ ๊ฐ๋ฅ)
plt.imshow(img[...,0])
plt.colorbar(location='left') #left, right(default), top, bottom
์ต์๊ฐ, ์ต๋๊ฐ ์ค์
plt.imshow(img[...,0], vmin=50, vmax=100)
plt.colorbar()
Grayscale
plt.imshow(img[...,0], cmap='gray')
Set title
plt.imshow(img)
plt.title('dog')
x ์ถ label, y ์ถ label ์ค์
plt.imshow(img)
plt.xlabel('x-axis')
plt.ylabel('y-axis')
๋๊ธ ์์ ๊ธฐ
plt.imshow(img)
plt.axis('off')
Subplot (์ด๋ฏธ์ง ์ฌ๋ฌ๊ฐ ๋์ฐ๊ธฐ)
img2 = cv2.imread('cat.jpg')
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2RGB)
plt.figure(figsize=(10, 4))
plt.subplot(1, 2, 1)
plt.imshow(img)
plt.subplot(1, 2, 2)
plt.imshow(img2)
* Subplot title & ์ ์ฒด title (suptitle)
plt.figure(figsize=(10, 4))
plt.subplot(1, 2, 1)
plt.imshow(img)
plt.title('dog')
plt.subplot(1, 2, 2)
plt.imshow(img2)
plt.title('cat')
plt.suptitle('animals')
๋ฐ์ํ
'๐ Python & library > Etc.' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Optuna] ๋ฅ๋ฌ๋ ํ์ดํผํ๋ผ๋ฏธํฐ ์ต์ ํํ๊ธฐ (1) | 2023.12.10 |
---|---|
[Tensorboard] ์ฐจํธ ์๊น ๋ณ๊ฒฝํ๊ธฐ (0) | 2022.10.12 |
[h5py] hdf5 ์๊ฐ, h5py ์ฌ์ฉ๋ฒ ๊ฐ๋จ ์ ๋ฆฌ (0) | 2021.12.14 |