matplotlib&seaborn

Matplotlib.pyplot.savefig 가 빈화면으로 저장될 때, 해결법!

오늘은 집 2021. 11. 28. 12:25

Matplotlib.pyplot.savefig를 했을 때 빈화면으로 저장될때가 있다. 이럴때 는 순서의 문제이다. 아래의 예를 봐보자.

 

1. 잘못된 순서로 실행했을 때

<figure size 432x288 with 0 axes> 라고 뜨고, 아래와 같이 빈화면으로 저장된다.

 

 

 

2. 해결법

plt.savefig를 plt.show보다 앞에 적어주자.

이렇게 순서를 바꾸어주면 잘 저장됨을 알 수 있다.

 

 

참고자료 : 스택오버플로우

https://stackoverflow.com/questions/9012487/matplotlib-pyplot-savefig-outputs-blank-image

 

Matplotlib (pyplot) savefig outputs blank image

I am trying to save plots I make using matplotlib; however, the images are saving blank. Here is my code: plt.subplot(121) plt.imshow(dataStack, cmap=mpl.cm.bone) plt.subplot(122) y = copy.deepc...

stackoverflow.com