2013-11-02 2 views
5

GUI로 열지 않고 3D 분산 플롯을 저장해야하는 작은 프로그램을 실행하려고합니다. 문제는 두 가지 모두를 수행한다는 것입니다! 내가 아주 많이 나는 음모가 GUI를 오픈하지 않고 내 음모의 저장된 이미지를 얻을 수있는 방법을 알고 싶습니다파이썬 : 플롯을 저장하고 GUI에서 열지 마십시오.

from matplotlib import pyplot 
from scipy import math 
from mpl_toolkits.mplot3d import Axes3D 

fig = pyplot.figure() 
ax = fig.add_subplot(111, projection='3d')   
ax.scatter(xPosition, yPosition, zPosition, c = velocity, s = mass) 
ax.set_xlim3d(-plotSize, plotSize) 
ax.set_ylim3d(-plotSize, plotSize) 
ax.set_zlim3d(-plotSize, plotSize) 
pyplot.savefig('plot.png') 

: 이것은 내가 이야기하고있는 코드의 조각이다. Saullo 카스트로 hilghlight로

+2

처음에는''import matplotlib''와''matplotlib.use ('Agg')''를 추가하십시오. "헤드리스"백엔드가 가능해야합니다. 필자의 경우 – fjarri

+0

, Windows에서 IDE (spe)를 실행하면 스크립트가 그림을 열지 않습니다. 내가''pyplot.show()'를 구체화 할 필요가있는 모습을 보러 간다. – joaquin

+0

내가 스파이더에서 일하고 있기 때문일까? –

답변

2

당신은() pylab.ioff 사용해야 때마다 당신은 그림을 사용 pylab.savefig ('file.png')를 저장합니다. 그림이 필요 없으면 현재 그림 (및 여유 메모리)을 닫으려면 pylab.close()를 수행하십시오.

from matplotlib import pyplot 
from mpl_toolkits.mplot3d import Axes3D 
pyplot.ioff() 
fig = pyplot.figure() 
# HERE your code to add things in the figure 
pyplot.savefig('file.png') 
pyplot.close() 
관련 문제