Python:保存绘图而不是在GUI中打开它

Dav*_*VdH 5 python matplotlib

我正在尝试运行一个应该保存我的3D散点图的程序,而不是在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')
Run Code Online (Sandbox Code Playgroud)

我非常想知道如何在没有用gui打开情节的情况下获得我的情节的保存图像.