fipy.viewers.matplotlibViewer.matplotlibStreamViewer¶
Classes
|
Displays a stream plot of a 2D rank-1 CellVariable or FaceVariable object using Matplotlib |
- class fipy.viewers.matplotlibViewer.matplotlibStreamViewer.MatplotlibStreamViewer(vars, title=None, log=False, limits={}, axes=None, figaspect='auto', density=1, linewidth=None, color=None, cmap=None, norm=None, arrowsize=1, arrowstyle='-|>', minlength=0.1, **kwlimits)¶
Bases:
AbstractMatplotlib2DViewer
Displays a stream plot of a 2D rank-1 CellVariable or FaceVariable object using Matplotlib
One issue is that this Viewer relies on scipy.interpolate.griddata, which interpolates on the convex hull of the data. The results is that streams are plotted across any concavities in the mesh.
Another issue is that it does not seem possible to remove the streams without calling cla(), which means that different set of streams cannot be overlaid.
>>> import fipy as fp >>> mesh = fp.Grid2D(nx=50, ny=100, dx=0.1, dy=0.01) >>> x, y = mesh.cellCenters >>> xyVar = fp.CellVariable(mesh=mesh, name="x y", value=x * y) >>> k = fp.Variable(name="k", value=1.) >>> viewer = MatplotlibStreamViewer(vars=fp.numerix.sin(k * xyVar).grad, ... title="MatplotlibStreamViewer test") >>> for kval in fp.numerix.arange(1, 10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer = MatplotlibStreamViewer(vars=fp.numerix.sin(k * xyVar).faceGrad, ... title="MatplotlibStreamViewer test") >>> from builtins import range >>> for kval in range(10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer.cmap = "ocean" >>> viewer.log = True
>>> viewer.title = "MatplotlibStreamViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
>>> import fipy as fp >>> mesh = (fp.Grid2D(nx=5, ny=10, dx=0.1, dy=0.1) ... + (fp.Tri2D(nx=5, ny=5, dx=0.1, dy=0.1) ... + ((0.5,), (0.2,)))) >>> x, y = mesh.cellCenters >>> xyVar = fp.CellVariable(mesh=mesh, name="x y", value=x * y) >>> k = fp.Variable(name="k", value=1.) >>> viewer = MatplotlibStreamViewer(vars=fp.numerix.sin(k * xyVar).grad, ... title="MatplotlibStreamViewer test") >>> for kval in fp.numerix.arange(1, 10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer = MatplotlibStreamViewer(vars=fp.numerix.sin(k * xyVar).faceGrad, ... title="MatplotlibStreamViewer test") >>> from builtins import range >>> for kval in range(10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer.cmap = "ocean" >>> viewer.log = True
>>> viewer.title = "MatplotlibStreamViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
Creates a MatplotlibStreamViewer.
- Parameters:
vars (
CellVariable
orFaceVariable
) – rank-1 Variable to displaytitle (
str
, optional) – displayed at the top of the Viewer windowlog (
bool
, optional) – if True, arrow length goes at the base-10 logarithm of the magnitudelimits (
dict
, optional) – a (deprecated) alternative to limit keyword argumentsxmin (
float
) – displayed range of data. Any limit set to a (default) value of None will autoscale.xmax (
float
) – displayed range of data. Any limit set to a (default) value of None will autoscale.ymin (
float
) – displayed range of data. Any limit set to a (default) value of None will autoscale.ymax (
float
) – displayed range of data. Any limit set to a (default) value of None will autoscale.datamin (
float
) – displayed range of data. Any limit set to a (default) value of None will autoscale.datamax (
float
) – displayed range of data. Any limit set to a (default) value of None will autoscale.axes (
Axes
, optional) – if not None, vars will be plotted into this Matplotlib Axes objectfigaspect (
float
, optional) – desired aspect ratio of figure. If arg is a number, use that aspect ratio. If arg is auto, the aspect ratio will be determined from the Variable’s mesh.density (
float
ortuple
offloat
, optional) – Controls the closeness of streamlines. Whendensity = 1
, the domain is divided into a 30x30 grid. density linearly scales this grid. Each cell in the grid can have, at most, one traversing streamline. For different densities in each direction, use a tuple (density_x, density_y).linewidth (array_like or
CellVariable
orFaceVariable
, optional) – The width of the stream lines. With a rank-0 CellVariable or FaceVariable the line width can be varied across the grid. The MeshVariable must have the same type and be defined on the same Mesh as vars.color (
str
orCellVariable
orFaceVariable
, optional) – The streamline color as a matplotlib color code or a field of numbers. If given a rank-0 CellVariable or FaceVariable, its values are converted to colors using cmap and norm. The MeshVariable must have the same type and be defined on the same Mesh as vars.cmap (
Colormap
, optional) – Colormap used to plot streamlines and arrows. This is only used if color is a MeshVariable.norm (
Normalize
, optional) – Normalize object used to scale luminance data to 0, 1. IfNone
, stretch (min, max) to (0, 1). Only necessary when color is a MeshVariable.arrowsize (
float
, optional) – Scaling factor for the arrow size.arrowstyle (
str
, optional) – Arrow style specification. See ~matplotlib.patches.FancyArrowPatch.minlength (
float
, optional) – Minimum length of streamline in axes coordinates.
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- property id¶
The Matplotlib
Figure
number.
- property kwargs¶
keyword arguments to pass to
streamplot()
.
- plot(filename=None)¶
Update the display of the viewed variables.
- Parameters:
filename (
str
) – If not None, the name of a file to save the image into.
- plotMesh(filename=None)¶
Display a representation of the mesh
- Parameters:
filename (
str
) – If not None, the name of a file to save the image into.
- setLimits(limits={}, **kwlimits)¶
Update the limits.
- Parameters:
limits (
dict
, optional) – a (deprecated) alternative to limit keyword argumentsxmin (
float
, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.xmax (
float
, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.ymin (
float
, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.ymax (
float
, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.zmin (
float
, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.zmax (
float
, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.datamin (
float
, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.datamax (
float
, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.