티스토리 뷰

figure

figure: 그래프가 그려지는 가장 큰 액자의 개념

axes : 하나의 그래프. 하나의 figure에 여러 개의 axes를 가질 수 있음

axis: 축. 하나의 axes는 x축, y축(2개의 axis)를 갖는다.

 

figure 함수

크기 지정

- figure의 크기를 지정함

- plt.figure(figsize=(가로, 세로))

import matplotlib.pylab as plt

plt.figure(figsize=(10, 5)

 

그래프 x축, y축 범위 지정

- 그래프(axes)의 x축 y축에서 표현될 최소, 최대값을 지정함

- plt.xlim(최소, 최대)

- plt.ylim(최소, 최대)

import matplotlib.pylab as plt

plt.figure(figsize=(10, 5))
plt.plot(x, y, color="darkblue", linewidth=3, linestyle="--", marker="o", ms=15, mec="orange", mew=3, mfc="yellow")
plt.xlim(0, 50)
plt.ylim(0, 10)
plt.show()

 

그래프 x축 ,y축, 제목 텍스트 지정

- plt.xlabel('X축')

- plt.ylabel('Y축')

- plt.title('타이틀')

- 텍스트의 폰트 옵션은 rc 함수로 조정 가능

plt.figure(figsize=(15, 5))
font={'family':'monospace', 'weight':'bold', 'size':30}
plt.rc('font', **font)     # 폰트 사이즈 변경
plt.plot(x, y, color="darkblue", linewidth=3, linestyle="--", marker="o", ms=15, mec="orange", mew=3, mfc="yellow")
plt.xlabel("X")
plt.ylabel("Y")
plt.title("title")
plt.show()

 

X축, Y축 눈금(tick) 지정

- 그래프에서 축에 표시되는 눈금의 범위와 개수를 설정할 수 있음

- plt.xticks(np. linespace(최소값, 최대값, 눈금 개수)

- plt.yticks(np. linespace(최소값, 최대값, 눈금 개수)

 

범례(legend) 설정

- 그래프의 범례 텍스트와 위치를 설정할 수 있음

- 위치를 설정하지 않으면, 표시되지 않음

- plt.plot(label=텍스트)

- plt.legend(loc=위치명)

- loc = [best, upper right, upper left, lower left, lower right, right, center left, center right, lower center, upper center, center]

x = np.array([10, 20, 30, 40, 50, 60, 70, 80])
y = np.array([1, 3, 5, 7, 9, 11, 13, 15])
plt.plot(x, y, label='1번 그래프')
plt.legend(loc='center left')
plt.show()

 

댓글