잠토의 잠망경

[OpenCV] matplotlib 본문

공부/Python

[OpenCV] matplotlib

잠수함토끼 2019. 1. 2. 21:18

matplotlib

하기 내용을 바탕으로 제 나름 재구성하였습니다.
https://datascienceschool.net/view-notebook/d0b1637803754bb083b5722c9f2209d0/

구조

Figure>Axes>Axis

객체 내용
Figure 그림이 그려지는 캔버스 종이
Axes 하나의 플롯
Axis 축(가로, 세로)
from matplotlib import pyplot as plt
import numpy as np

np.random.seed(0)

plt.title('normal')
plt.plot(np.random.random(100)
plt.show()

f1 = plt.figure()    # 위와 동일함 
plt.title('figure')
plt.plot(np.random.random(100)
plt.show()

현재 figure 얻기

gcf 사용함

f1 = plt.figure(1)
f2 = plt.gcf() # get current figure

figure 2개 chart그리기

하나의 윈도우 (figure)안에 여러개의 axes를 추가 하기 위해서는 subplot()를 이용한다.

기본 base는 1 부터 시작이다.

# 2x1인경우
ax1 = plt.subplot(2,1,1)
plt.plot(np.random.random(100))

ax2 = plt.subplot(2,1,2)
plt.plot(np.random.random(100))

plt.tight_layout() # axes간 간격 자동 정렬
plt.show()

subplot() 함수의 인자를 (행,열,인덱스) 에서 행열인덱스 로 활용하는 방법

# 2x1인경우
ax1 = plt.subplot(211)
plt.plot(np.random.random(100))

ax2 = plt.subplot(212)
plt.plot(np.random.random(100))

plt.tight_layout()
plt.show()

subplots()를 활용하여 접근하기

# 2x1인경우
fig, axes = plt.subplots(2,1)
axes[0,0] .plot(np.random.random(100))
axes[1,0] .plot(np.random.random(100))

plt.tight_layout()
plt.show()

하나의 chart에 선 두 개 그리기

twinx() 를 활용하여 그린다.

fig, ax0 = plt.subplots()

ax1 = ax0.twinx()

ax0.plot([10,11,12,13,14], 'r-', label='y0') # r- : red line
ax1.plot([12,13,140, 190], 'b:', label='y1') # b: : blue dotting line

ax0.set_ylabel('y0')
ax1.set_ylabel('y1')

plt.show()

ROI(Region of Interest)

ROI는 한국어로 관심 영역이다.

Comments