IT박스

matplotlib에 플롯이 완료되었음을 어떻게 알 수 있습니까?

itboxs 2020. 6. 15. 21:58
반응형

matplotlib에 플롯이 완료되었음을 어떻게 알 수 있습니까?


다음 코드는 두 개의 PostScript (.ps) 파일로 플로팅 되지만 두 번째 파일에는 두 줄이 모두 포함되어 있습니다.

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

plt.subplot(111)
x = [1,10]
y = [30, 1000]
plt.loglog(x, y, basex=10, basey=10, ls="-")
plt.savefig("first.ps")


plt.subplot(111)
x = [10,100]
y = [10, 10000]
plt.loglog(x, y, basex=10, basey=10, ls="-")
plt.savefig("second.ps")

matplotlib에게 두 번째 줄거리에 대해 새로 시작하도록하려면 어떻게해야합니까?


당신은 사용할 수 있습니다 figure예를 들어, 새로운 플롯을 만들거나 사용하는 close첫 번째 플롯 후.


명확한 그림 명령이 있으며 다음과 같이해야합니다.

plt.clf()

같은 그림에 여러 개의 하위 그림이있는 경우

plt.cla()

현재 축을 지 웁니다.


David Cournapeau에서 언급했듯이 figure ()를 사용하십시오.

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

plt.figure()
x = [1,10]
y = [30, 1000]
plt.loglog(x, y, basex=10, basey=10, ls="-")
plt.savefig("first.ps")


plt.figure()
x = [10,100]
y = [10, 10000]
plt.loglog(x, y, basex=10, basey=10, ls="-")
plt.savefig("second.ps")

또는 동일한 플롯, 다른 위치에 대해 subplot (121) / subplot (122).

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

plt.subplot(121)
x = [1,10]
y = [30, 1000]
plt.loglog(x, y, basex=10, basey=10, ls="-")

plt.subplot(122)
x = [10,100]
y = [10, 10000]
plt.loglog(x, y, basex=10, basey=10, ls="-")
plt.savefig("second.ps")

plt.hold(False)첫 번째 plt.plot 전에 입력 하면 원래 코드를 유지할 수 있습니다.


예를 들어 웹 애플리케이션 (예 : ipython)에서 Matplotlib을 대화식으로 사용하는 경우

plt.show()

instead of plt.close() or plt.clf().


If none of them are working then check this.. say if you have x and y arrays of data along respective axis. Then check in which cell(jupyter) you have initialized x and y to empty. This is because , maybe you are appending data to x and y without re-initializing them. So plot has old data too. So check that..

참고URL : https://stackoverflow.com/questions/741877/how-do-i-tell-matplotlib-that-i-am-done-with-a-plot

반응형