mayavi mlab.savefig() gives an empty image

一世执手 提交于 2019-11-30 17:11:28

问题


I am trying to learn mayavi2 for python and can not get my savefig to show my plots. I found this example code:

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()

Now I want to save the figure, so I add:

mlab.savefig(filename='test.png')

This saves an all gray image to test.png. What must I do to get the actual image to save?


回答1:


This is probably the same issue that results from just using matplotlib, the best option is probably to save before you show.



来源:https://stackoverflow.com/questions/16543634/mayavi-mlab-savefig-gives-an-empty-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!