discretize.View.TensorView

class discretize.View.TensorView[source]

Bases: object

Provides viewing functions for TensorMesh

This class is inherited by TensorMesh

Methods

plotGrid([ax, nodes, faces, centers, edges, …])

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

plotImage(v)

Plots scalar fields on the given mesh.

plotSlice(v[, v_type, normal, ind, grid, …])

Plots a slice of a 3D mesh.

plot_3d_slicer(v[, xslice, yslice, zslice, …])

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

Attributes

Methods

TensorView.plotGrid(ax=None, nodes=False, faces=False, centers=False, edges=False, lines=True, show_it=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

  • show_it (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, show_it=True)

(Source code, 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, show_it=True)

(Source code, 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
  • v_type (str) – type of vector (‘CC’, ‘N’, ‘F’, ‘Fx’, ‘Fy’, ‘Fz’, ‘E’, ‘Ex’, ‘Ey’, ‘Ez’)

  • ax (matplotlib.axes.Axes) – axis to plot to

  • show_it (bool) – call plt.show()

3D Inputs:

Parameters
  • numbering (bool) – show numbering of slices, 3D only

  • annotation_color (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, show_it=True)

(Source code, 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, annotation_color='k', show_it=True)

(Source code, png, pdf)

../../_images/discretize-View-TensorView-4.png
TensorView.plotSlice(v, v_type='CC', normal='Z', ind=None, grid=False, view='real', ax=None, clim=None, show_it=False, pcolor_opts=None, stream_opts=None, grid_opts=None, range_x=None, range_y=None, sample_grid=None, stream_threshold=None, stream_thickness=None, **kwargs)[source]

Plots a slice of a 3D mesh.

import discretize
from pymatsolver import Solver
import numpy as np
hx = [(5, 2, -1.3), (2, 4), (5, 2, 1.3)]
hy = [(2, 2, -1.3), (2, 6), (2, 2, 1.3)]
hz = [(2, 2, -1.3), (2, 6), (2, 2, 1.3)]
M = discretize.TensorMesh([hx, hy, hz])
q = np.zeros(M.vnC)
q[[4, 4], [4, 4], [2, 6]]=[-1, 1]
q = discretize.utils.mkvc(q)
A = M.faceDiv * M.cellGrad
b = Solver(A) * (q)
M.plotSlice(M.cellGrad*b, 'F', view='vec', grid=True, show_it=True, pcolor_opts={'alpha':0.8})

(Source code, png, pdf)

../../_images/discretize-View-TensorView-5.png
TensorView.plot_3d_slicer(v, xslice=None, yslice=None, zslice=None, v_type='CC', view='real', axis='xy', transparent=None, clim=None, xlim=None, ylim=None, zlim=None, aspect='auto', grid=[2, 2, 1], pcolor_opts=None, fig=None, **kwargs)[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.