discretize.View.TensorView

class discretize.View.TensorView[source]

Bases: object

Provides viewing functions for TensorMesh

This class is inherited by TensorMesh

Methods

plotGrid(self[, ax, nodes, faces, centers, …]) Plot the nodal, cell-centered and staggered grids for 1,2 and 3 dimensions.
plotImage(v) Plots scalar fields on the given mesh.
plotSlice(self, v[, vType, normal, ind, …]) Plots a slice of a 3D mesh.
plot_3d_slicer(self, v[, xslice, yslice, …]) Plot slices of a 3D volume, interactively (scroll wheel).

Attributes

Methods

TensorView.plotGrid(self, ax=None, nodes=False, faces=False, centers=False, edges=False, lines=True, showIt=False, **kwargs)[source]

Plot the nodal, cell-centered and staggered grids for 1,2 and 3 dimensions.

Parameters:
  • nodes (bool) – plot nodes
  • faces (bool) – plot faces
  • centers (bool) – plot centers
  • edges (bool) – plot edges
  • lines (bool) – plot lines connecting nodes
  • showIt (bool) – call plt.show()
import discretize
import numpy as np
h1 = np.linspace(.1, .5, 3)
h2 = np.linspace(.1, .5, 5)
mesh = discretize.TensorMesh([h1, h2])
mesh.plotGrid(nodes=True, faces=True, centers=True, lines=True, showIt=True)

(Source code, png, hires.png, pdf)

../../_images/discretize-View-TensorView-1.png
import discretize
import numpy as np
h1 = np.linspace(.1, .5, 3)
h2 = np.linspace(.1, .5, 5)
h3 = np.linspace(.1, .5, 3)
mesh = discretize.TensorMesh([h1, h2, h3])
mesh.plotGrid(nodes=True, faces=True, centers=True, lines=True, showIt=True)

(Source code, png, hires.png, pdf)

../../_images/discretize-View-TensorView-2.png
TensorView.plotImage(v)[source]

Plots scalar fields on the given mesh.

Input:

Parameters:v (numpy.ndarray) – vector

Optional Inputs:

Parameters:
  • vType (str) – type of vector (‘CC’, ‘N’, ‘F’, ‘Fx’, ‘Fy’, ‘Fz’, ‘E’, ‘Ex’, ‘Ey’, ‘Ez’)
  • ax (matplotlib.axes.Axes) – axis to plot to
  • showIt (bool) – call plt.show()

3D Inputs:

Parameters:
  • numbering (bool) – show numbering of slices, 3D only
  • annotationColor (str) – color of annotation, e.g. ‘w’, ‘k’, ‘b’
import discretize
import numpy as np
M = discretize.TensorMesh([20, 20])
v = np.sin(M.gridCC[:, 0]*2*np.pi)*np.sin(M.gridCC[:, 1]*2*np.pi)
M.plotImage(v, showIt=True)

(Source code, png, hires.png, pdf)

../../_images/discretize-View-TensorView-3.png
import discretize
import numpy as np
M = discretize.TensorMesh([20, 20, 20])
v = np.sin(M.gridCC[:, 0]*2*np.pi)*np.sin(M.gridCC[:, 1]*2*np.pi)*np.sin(M.gridCC[:, 2]*2*np.pi)
M.plotImage(v, annotationColor='k', showIt=True)

(Source code, png, hires.png, pdf)

../../_images/discretize-View-TensorView-4.png
TensorView.plotSlice(self, v, vType='CC', normal='Z', ind=None, grid=False, view='real', ax=None, clim=None, showIt=False, pcolorOpts=None, streamOpts=None, gridOpts=None, range_x=None, range_y=None, sample_grid=None, stream_threshold=None, stream_thickness=None)[source]

Plots a slice of a 3D mesh.

(Source code, png, hires.png, pdf)

../../_images/discretize-View-TensorView-5.png
TensorView.plot_3d_slicer(self, 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, fig=None)[source]

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

If called from a notebook, make sure to set

%matplotlib notebook

See the class discretize.View.Slicer for more information.

It returns nothing. However, if you need the different figure handles you can get it via

fig = plt.gcf()

and subsequently its children via

fig.get_children()

and recursively deeper, e.g.,

fig.get_children()[0].get_children().

One can also provide an existing figure instance, which can be useful for interactive widgets in Notebooks. The provided figure is cleared first.