class discretize.View.Slicer(mesh, v, xslice=None, yslice=None, zslice=None, vType='CC', view='real', axis='xy', transparent=None, clim=None, xlim=None, ylim=None, zlim=None, aspect='auto', grid=[2, 2, 1], pcolorOpts=None)[source]

Bases: object

Plot slices of a 3D volume, interactively (scroll wheel).

If called from a notebook, make sure to set

%matplotlib notebook

The straight forward usage for the Slicer is through, e.g., a TensorMesh-mesh, by accessing its mesh.plot_3d_slicer.

If you, however, call this class directly, you have first to initiate a figure, and afterwards connect it:

>>> # You have to initialize a figure
>>> fig = plt.figure()
>>> # Then you have to get the tracker from the Slicer
>>> tracker = discretize.View.Slicer(mesh, Lpout)
>>> # Finally you have to connect the tracker to the figure
>>> fig.canvas.mpl_connect('scroll_event', tracker.onscroll)
>>> plt.show()


v : array
Data array of length self.nC.
xslice, yslice, zslice : floats, optional
Initial slice locations (in meter); defaults to the middle of the volume.
vType: str
Type of visualization. Default is ‘CC’. One of [‘CC’, ‘Fx’, ‘Fy’, ‘Fz’, ‘Ex’, ‘Ey’, ‘Ez’].
view : str
Which component to show. Defaults to ‘real’. One of [‘real’, ‘imag’, ‘abs’].
axis : ‘xy’ (default) or ‘yx’
‘xy’: horizontal axis is x, vertical axis is y. Reversed otherwise.
transparent : ‘slider’ or list of floats or pairs of floats, optional
Values to be removed. E.g. air, water. If single value, only exact matches are removed. Pairs are treated as ranges. E.g. [0.3, [1, 4], [-np.infty, -10]] removes all values equal to 0.3, all values between 1 and 4, and all values smaller than -10. If ‘slider’ is provided it will plot an interactive slider to choose the shown range.
clim : None or list of [min, max]
For pcolormesh (vmin, vmax).
xlim, ylim, zlim : None or list of [min, max]
Axis limits.
aspect : ‘auto’, ‘equal’, or num

Aspect ratio of subplots. Defaults to ‘auto’.

A list of two values can be provided. The first will be for the XY-plot, the second for the XZ- and YZ-plots, e.g. [‘equal’, 2] to have the vertical dimension exaggerated by a factor of 2.

WARNING: For anything else than ‘auto’, unexpected things might happen
when zooming, and the subplot-arrangement won’t look pretty.
grid : list of 3 int
Number of cells occupied by x, y, and z dimension on plt.subplot2grid.
pcolorOpts : dictionary
Passed to pcolormesh.


onscroll(self, event) Update index and data when scrolling.
update_xy(self) Update plot for change in Z-index.
update_xz(self) Update plot for change in Y-index.
update_zy(self) Update plot for change in X-index.

Examples using discretize.View.Slicer



Slicer.onscroll(self, event)[source]

Update index and data when scrolling.


Update plot for change in Z-index.


Update plot for change in Y-index.


Update plot for change in X-index.