我正在尝试为 python 学习 mayavi2,但无法让我的 savefig 显示我的情节。我找到了这个示例代码:
from numpy import pi, sin, cos, mgrid
dphi, dtheta = pi/250.0, pi/250.0
[phi,theta] = mgrid[0:pi+dphi*1.5:dphi,0:2*pi+dtheta*1.5:dtheta]
m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;
r = sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7
x = r*sin(phi)*cos(theta)
y = r*cos(phi)
z = r*sin(phi)*sin(theta)
# View it.
from mayavi import mlab
a= mlab.mesh(x, y, z)
mlab.show()
现在我想保存这个数字,所以我添加:
mlab.savefig(filename='test.png')
这会将全灰色图像保存到 test.png。我必须做什么才能保存实际图像?