본문 바로가기
파이썬

파이썬 내 plt.savefig가 작동하지 않는 이유는 무엇입니까?

by º기록 2020. 11. 22.
반응형

다음과 같이 간단한 파이썬 코드가 있습니다.

import numpy as np
import matplotlib.pyplot as plt

"""
Here are the solutions and the plot.
"""

# Create the axis and plot.
plt.axis([0, 10, 0, 10])
axis_x = range(1, 11)
grd = [1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 9.1, 10.1]
grd2 = [1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2, 8.2, 9.2, 10.2]
plt.plot(axis_x, grd, '-g', label='BR1')
plt.plot(axis_x, grd2, '-b', label='BR2')
plt.legend(loc='upper left')
plt.grid()
plt.show()

# Save the results vector to a text file.
np.savetxt('test.out', (grd, grd2))

# Save the figure as '.eps' file.
plt.savefig('expl.pdf', format='pdf', dpi=1200)

출력 파일 expl.pdf 및 / 또는 test.out 을 열면 비어 있고 아무것도 없습니다. 왜?

감사.

 

해결 방법

 

plt.show () 로 표시된 이미지를 닫으면 이미지가 닫히고 메모리에서 해제됩니다.

show 를 호출하기 전에 savefig savetxt 를 호출해야합니다.

 

참조 페이지 https://stackoverflow.com/questions/30765455

 

 

반응형

댓글