Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep window in Mayavi after running python script

I'm trying to run a python script that generates a plot using Mayavi.

I'm using the following example code to generate an iso-surface plot:

from mayavi import mlab
def test_contour3d():
    x, y, z = numpy.ogrid[-5:5:64j, -5:5:64j, -5:5:64j]
    scalars = x * x * 0.5 + y * y + z * z * 2.0
    obj = mlab.contour3d(scalars, contours=4, transparent=True)
    return obj

test_contour3d()

The plot looks great but it immediately disappears. I read that you need to include the following code in order to make the plot stick around:

import mayavi
v = mayavi.mayavi()
v.master.wait_window()

This seems reasonable enough, but when I try this, python reports:

AttributeError: 'module' object has no attribute 'mayavi'

any ideas? I'm using the standard Enthought Python on OS X.

like image 485
DanHickstein Avatar asked Sep 17 '26 08:09

DanHickstein


1 Answers

Use mlab.show() to keep the plot frame open.

like image 63
JulienD Avatar answered Sep 18 '26 22:09

JulienD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!