Search code examples
pythonmayavi

How to remove the red frame and white arrow in scalar_cut_plane when using mayavi?


Hi I want to use mayavi to visualize the data in structured grid in a cut plane.

To exemplify this, I have the following code obtained from http://docs.enthought.com/mayavi/mayavi/auto/example_structured_grid.html written by Eric Jones

#!/usr/bin/env python  
import numpy as np
from numpy import cos, sin, pi
from tvtk.api import tvtk
from mayavi import mlab

def generate_annulus(r=None, theta=None, z=None):
    # Find the x values and y values for each plane.
    x_plane = (cos(theta)*r[:,None]).ravel()
    y_plane = (sin(theta)*r[:,None]).ravel()

    # Allocate an array for all the points.  We'll have len(x_plane)
    # points on each plane, and we have a plane for each z value, so
    # we need len(x_plane)*len(z) points.
    points = np.empty([len(x_plane)*len(z),3])

    # Loop through the points for each plane and fill them with the
    # correct x,y,z values.
    start = 0
    for z_plane in z:
        end = start + len(x_plane)
        # slice out a plane of the output points and fill it
        # with the x,y, and z values for this plane.  The x,y
        # values are the same for every plane.  The z value
        # is set to the current z
        plane_points = points[start:end]
        plane_points[:,0] = x_plane
        plane_points[:,1] = y_plane
        plane_points[:,2] = z_plane
        start = end

    return points

# Make the data.
dims = (51, 25, 25)
# The coordinates
theta = np.linspace(0, 2*np.pi, dims[0])
# 'y' corresponds to varying 'r'
r = np.linspace(1, 10, dims[1])
z = np.linspace(0, 5, dims[2])
pts = generate_annulus(r, theta, z)

# Make the grid
sgrid = tvtk.StructuredGrid(dimensions=dims)
sgrid.points = pts
s = np.sqrt(pts[:,0]**2 + pts[:,1]**2 + pts[:,2]**2)
sgrid.point_data.scalars = np.ravel(s.copy())
sgrid.point_data.scalars.name = 'scalars'

d = mlab.pipeline.add_dataset(sgrid)
mlab.pipeline.scalar_cut_plane(d)
mlab.show()

However, I would like to get rid of the annoying red frame and the white arrow in when saving the plot. How do I do this?

I first tried to use the module mlab.pipeline.scalar_field to do this, but I got an error saying that I needed to specify the data as an array. I've also searched the gui to see if there is somewhere I can turn this off, but i cannot seem to find it


Solution

  • You can simply disable the widget. Note however that this means that you cannot drag around your plane anymore (but it sounds like you do not want to have this functionality)

    In last line, change

    mlab.pipeline.scalar_cut_plane(d)
    

    with

    cut = mlab.pipeline.scalar_cut_plane(d)
    cut.implicit_plane.widget.enabled = False
    

    It is also possible to do this in the GUI.

    Go to the ScalarCutPlane in the pipeline menu, then disable the widget by unchecking "enable" in the tab "ImplicitPlane".

    ...and there you go