본문 바로가기
파이썬/파이썬 시각화

Matploblib) 데이터 시각화 2편, 그래프 저장, 좌표 입력, 다중데이터, legend(label) 응용

by SeH_ 2023. 1. 17.
반응형

나도코딩 유튜브를 참고하여 적었습니다!


1. 그래프 저장하는 방법입니다.

plt.savefig('graph.png', dpi = 100) # graph.png로 저장된다

*dpi는 확대 기능을 한다고 생각하시면 됩니다. 

 

 

2. 그래프에 좌표를 기입하는 방법입니다. 

for idx, txt in enumerate(y):
    plt.text(x[idx] ,y[idx] + 0.3 ,txt, ha = 'center',color = 'blue')
    # y 데이터 [2,4,8] > txt, 0, 1, 2 > index

 

3. 다중 그래프를 그리는 방법입니다. 

plt.plot(days,az, label =  'az')
plt.plot(days,pfizer, label = '화이자', marker = 'o', ls = '--')
plt.plot(days,moderna, label = '모더나', marker = 's', ls = '-.')

plt.legend(loc = 'upper left')

파이썬 내장 함수인 ncol로 바꾸면 레전드가 더 이쁘게 적용됩니다. 

plt.legend(ncol = 3)

 

 

댓글