1

So I am trying to save a figure using Mayavi. The code is shown below.

mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0.5, 0.5, 0.5))
mlab.contour3d(i, a, d, abs(ber), contours=10, opacity=0.5, colormap='hot')
mlab.outline()
mlab.colorbar(orientation='vertical')

mlab.axes(color=(0.5,0.5,0.5), line_width=4, xlabel='I', ylabel='A', zlabel='D')
mlab.move(forward=-4, right=-4)

mlab.savefig('abc.png', figure=mlab.gcf(), magnification=2)
mlab.show()

The data gets rendered on the screen ok. For example: Screenshot

But when I do a savefig() unfortunately there seems to be a problem. I get a blank figure. I even tried to do a screenshot() and plot that using pylab.imshow() but that turned out to be blank as well. I even tried to save directly with the save button on the mlab window, and even this gives a blank image!

I have already checked [ mayavi mlab.savefig() gives an empty image ] but that doesnt seem to be doing the trick.

I am beginning to suspect that the backend is a problem. I am using wxPython on a Windows 7 system with a Qt backend. I also tried with pretty much all the backends I had, even with a normal non-interactive console and it doesnt work.

Does anyone have any experience with this??

Community
  • 1
  • 1
ssm
  • 5,277
  • 1
  • 24
  • 42
  • Assuming that I put in some random data for your data, the code snippet you have works for me just fine. What exactly do you mean by "I am using wxPython ... with a Qt backend" – aestrivex Feb 03 '14 at 23:08
  • From what I understand, the `savefig()` function simply does a screencapture directly from the screen. The backend displays the image on the screen. If there is a disparity between the capture process and the display process, then the image wont be captures. I have seen this in video capture before where the program renders directly using direct hardware access. With magnification = 2, I see the screen magnify the image and do a _capture_ but the data are all 0's. I think maybe something like this is going on. Not sure though. – ssm Feb 04 '14 at 00:54
  • Yes. But, if you were using wxpython, then I would imagine you would be using the wx backend. (Unless you are trying to say you have a mayavi window using the Qt backend embedded within a wxpython application?) I probably can't help you, but what happens if you do `magnification=1`? – aestrivex Feb 04 '14 at 01:05
  • Actually my wxPython comes with a number of pre-configured consoles, one of them uses the Qt backend. It says _IPython (Qt)_. So thats what I use for running the program. I generally use this because the default _wx_ backend gives problems with _pylab_ interaction. This should not be happening, but it does. Something is messed up with my installation somewehre! Ill try to do a clean reinstall and see if that helps. – ssm Feb 04 '14 at 01:45
  • `magnification=1` doesnt change anything. Initially I didnt have that parameter in. I put `magnification=2` simply as an additional check ... – ssm Feb 04 '14 at 01:47
  • Sorry, when I said _wxPython_, I really did mean _Python(x,y)_. Really sorry about the confusion. By bad. – ssm Feb 04 '14 at 01:57

1 Answers1

-2

Here the issue has been solved mayavi mlab.savefig() gives an empty image

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

Community
  • 1
  • 1
sfg
  • 1
  • even if the link has the answer. it help to copy the core or the most important parts with the question – MZaragoza Apr 01 '15 at 15:46
  • Thanks. On reinstalling my Python distribution (for various reasons) this problem seems to have disappeared. I dont know what exactly the problem was, but now it is no more. Thanks for your suggestion though. – ssm Apr 02 '15 at 00:57