fipy.viewers.matplotlibViewer package¶
Submodules¶
fipy.viewers.matplotlibViewer.matplotlib1DViewer module¶
- class fipy.viewers.matplotlibViewer.matplotlib1DViewer.Matplotlib1DViewer(vars, title=None, xlog=False, ylog=False, limits={}, legend='upper left', axes=None, **kwlimits)¶
Bases:
AbstractMatplotlibViewer
Displays a y vs. x plot of one or more 1D CellVariable objects using Matplotlib.
>>> import fipy as fp >>> mesh = fp.Grid1D(nx=100) >>> x, = mesh.cellCenters >>> xVar = fp.CellVariable(mesh=mesh, name="x", value=x) >>> k = fp.Variable(name="k", value=0.) >>> viewer = Matplotlib1DViewer(vars=(fp.numerix.sin(k * xVar) + 2, ... fp.numerix.cos(k * xVar / fp.numerix.pi) + 2), ... xmin=10, xmax=90, ... datamin=1.1, datamax=4.0, ... title="Matplotlib1DViewer test") >>> for kval in fp.numerix.arange(0, 0.3, 0.03): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer.cmap = "ocean" >>> viewer.log = True
>>> viewer.title = "Matplotlib1DViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
- Parameters:
vars (CellVariable or list) – CellVariable objects to plot
title (str, optional) – displayed at the top of the Viewer window
xlog (bool) – log scaling of x axis if True
ylog (bool) – log scaling of y axis if True
limits (dict) – a (deprecated) alternative to limit keyword arguments
xmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale. (ymin and ymax are synonyms for datamin and datamax).
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale. (ymin and ymax are synonyms for datamin and datamax).
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale. (ymin and ymax are synonyms for datamin and datamax).
datamax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale. (ymin and ymax are synonyms for datamin and datamax).
legend (str) – place a legend at the specified position, if not None
axes (Axes) – if not None, vars will be plotted into this Matplotlib
Axes
object
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property limits¶
- property lines¶
The collection of Matplotlib
Line2D
objects representing the plotted data.
- property log¶
Whether data has logarithmic scaling
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
fipy.viewers.matplotlibViewer.matplotlib2DContourViewer module¶
- class fipy.viewers.matplotlibViewer.matplotlib2DContourViewer.Matplotlib2DContourViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, number=None, levels=None, figaspect='auto', **kwlimits)¶
Bases:
AbstractMatplotlib2DViewer
Displays a contour plot of a 2D CellVariable object.
The Matplotlib2DContourViewer plots a 2D CellVariable using Matplotlib.
Creates a Matplotlib2DContourViewer.
- Parameters:
vars (CellVariable) – Variable to display
title (str, optional) – displayed at the top of the Viewer window
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
xmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
cmap (Colormap, optional) – the Colormap. Defaults to matplotlib.cm.jet
colorbar (bool, optional) – plot a color bar in specified orientation if not None
axes (Axes, optional) – if not None, vars will be plotted into this Matplotlib Axes object
number (int, optional) – Determines the number and positions of the contour lines / regions. (deprecated, use levels=).
levels (int or array-like, optional) – Determines the number and positions of the contour lines / regions. If an int n, tries to automatically choose no more than n+1 “nice” contour levels over the range of vars. If array-like, draw contour lines at the specified levels. The values must be in increasing order. E.g. to draw just the zero contour pass
levels=[0]
.figaspect (float) – 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.
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property levels¶
The number of automatically-chosen contours or their values.
- property limits¶
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
fipy.viewers.matplotlibViewer.matplotlib2DGridContourViewer module¶
- class fipy.viewers.matplotlibViewer.matplotlib2DGridContourViewer.Matplotlib2DGridContourViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, levels=None, figaspect='auto', **kwlimits)¶
Bases:
AbstractMatplotlib2DViewer
Displays a contour plot of a 2D CellVariable object.
The Matplotlib2DGridContourViewer plots a 2D CellVariable using Matplotlib.
>>> 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=0.) >>> viewer = Matplotlib2DGridContourViewer(vars=fp.numerix.sin(k * xyVar) * 1000 + 1002, ... ymin=0.1, ymax=0.9, ... # datamin=1.1, datamax=4.0, ... title="Matplotlib2DGridContourViewer test") >>> from builtins import range >>> for kval in range(10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer.levels = 2
>>> viewer.cmap = "ocean" >>> viewer.log = True
>>> viewer.title = "Matplotlib2DGridContourViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
Creates a Matplotlib2DViewer.
- Parameters:
vars (CellVariable) – the Variable to display.
title (str, optional) – displayed at the top of the Viewer window
limits (dict) – a (deprecated) alternative to limit keyword arguments
xmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
cmap (Colormap, optional) – the
Colormap
. Defaults to matplotlib.cm.jetcolorbar (bool, optional) – plot a color bar if not None
axes (Axes, optional) – if not None, vars will be plotted into this Matplotlib Axes object
levels (int or array-like, optional) – Determines the number and positions of the contour lines / regions. If an int n, tries to automatically choose no more than n+1 “nice” contour levels over the range of vars. If array-like, draw contour lines at the specified levels. The values must be in increasing order. E.g. to draw just the zero contour pass
levels=[0]
.figaspect (float, optional) – desired aspect ratio of figure. If a number, use that aspect ratio. If auto, the aspect ratio will be determined from the vars’s mesh.
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property levels¶
The number of automatically-chosen contours or their values.
- property limits¶
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
fipy.viewers.matplotlibViewer.matplotlib2DGridViewer module¶
- class fipy.viewers.matplotlibViewer.matplotlib2DGridViewer.Matplotlib2DGridViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)¶
Bases:
AbstractMatplotlib2DViewer
Displays an image plot of a 2D CellVariable object using Matplotlib.
>>> 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=0.) >>> viewer = Matplotlib2DGridViewer(vars=fp.numerix.sin(k * xyVar) * 1000 + 1002, ... ymin=0.1, ymax=0.9, ... # datamin=1.1, datamax=4.0, ... title="Matplotlib2DGridViewer 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 = "Matplotlib2DGridViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
Creates a Matplotlib2DGridViewer.
- Parameters:
vars (CellVariable) – the Variable to display.
title (str, optional) – displayed at the top of the Viewer window
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
cmap (Colormap, optional) – the
Colormap
. Defaults to matplotlib.cm.jetxmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
colorbar (bool, optional) – plot a color bar in specified orientation if not None
axes (Axes, optional) – if not None, vars will be plotted into this Matplotlib Axes object
figaspect (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.
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property limits¶
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
fipy.viewers.matplotlibViewer.matplotlib2DViewer module¶
- class fipy.viewers.matplotlibViewer.matplotlib2DViewer.Matplotlib2DViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)¶
Bases:
AbstractMatplotlib2DViewer
Displays a contour plot of a 2D CellVariable object.
The Matplotlib2DViewer plots a 2D CellVariable using Matplotlib.
>>> 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=0.) >>> viewer = Matplotlib2DViewer(vars=fp.numerix.sin(k * xyVar) * 1000 + 1002, ... ymin=0.1, ymax=0.9, ... # datamin=1.1, datamax=4.0, ... title="Matplotlib2DViewer 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 = "Matplotlib2DViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
Creates a Matplotlib2DViewer.
- Parameters:
vars (CellVariable) – the Variable to display.
title (str, optional) – displayed at the top of the Viewer window
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
cmap (Colormap, optional) – the
Colormap
. Defaults to matplotlib.cm.jetxmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
colorbar (bool, optional) – plot a color bar in specified orientation if not None
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.
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property collection¶
The Matplotlib
PolyCollection
representing the cells.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property limits¶
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
fipy.viewers.matplotlibViewer.matplotlibSparseMatrixViewer module¶
fipy.viewers.matplotlibViewer.matplotlibStreamViewer module¶
- 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 or FaceVariable) – rank-1 Variable to display
title (str, optional) – displayed at the top of the Viewer window
log (bool, optional) – if True, arrow length goes at the base-10 logarithm of the magnitude
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
xmin (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 object
figaspect (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 or (float, float), optional) – Controls the closeness of streamlines. When
density = 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 or FaceVariable, 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 or CellVariable or FaceVariable, 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. If
None
, 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
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property kwargs¶
keyword arguments to pass to
streamplot()
.
- property limits¶
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
fipy.viewers.matplotlibViewer.matplotlibVectorViewer module¶
- class fipy.viewers.matplotlibViewer.matplotlibVectorViewer.MatplotlibVectorViewer(vars, title=None, scale=None, sparsity=None, log=False, limits={}, axes=None, figaspect='auto', **kwlimits)¶
Bases:
AbstractMatplotlib2DViewer
Displays a vector plot of a 2D rank-1 CellVariable or FaceVariable object using Matplotlib
>>> 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 = MatplotlibVectorViewer(vars=fp.numerix.sin(k * xyVar).grad, ... title="MatplotlibVectorViewer test") >>> for kval in fp.numerix.arange(1, 10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=fp.numerix.sin(k * xyVar).faceGrad, ... title="MatplotlibVectorViewer test") >>> from builtins import range >>> for kval in range(10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> for sparsity in numerix.arange(5000, 0, -500): ... viewer.quiver(sparsity=sparsity) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer.cmap = "ocean" >>> viewer.log = True
>>> viewer.title = "MatplotlibVectorViewer 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 = MatplotlibVectorViewer(vars=fp.numerix.sin(k * xyVar).grad, ... title="MatplotlibVectorViewer test") >>> for kval in fp.numerix.arange(1, 10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=fp.numerix.sin(k * xyVar).faceGrad, ... title="MatplotlibVectorViewer test") >>> from builtins import range >>> for kval in range(10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> for sparsity in numerix.arange(5000, 0, -500): ... viewer.quiver(sparsity=sparsity) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer.cmap = "ocean" >>> viewer.log = True
>>> viewer.title = "MatplotlibVectorViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
Creates a Matplotlib2DViewer.
- Parameters:
vars (CellVariable or FaceVariable) – rank-1 Variable to display
title (str, optional) – displayed at the top of the Viewer window
scale (float, optional) – if not None, scale all arrow lengths by this value
sparsity (int, optional) – if not None, then this number of arrows will be randomly chosen (weighted by the cell volume or face area)
log (bool, optional) – if True, arrow length goes at the base-10 logarithm of the magnitude
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
xmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamax (float, optional) – 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 object
figaspect (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.
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property limits¶
- 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.
- quiver(sparsity=None, scale=None)¶
- setLimits(limits={}, **kwlimits)¶
Update the limits.
- Parameters:
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
fipy.viewers.matplotlibViewer.matplotlibViewer module¶
- class fipy.viewers.matplotlibViewer.matplotlibViewer.AbstractMatplotlibViewer(vars, title=None, figaspect=1.0, cmap=None, colorbar=None, axes=None, log=False, **kwlimits)¶
Bases:
AbstractViewer
Attention
This class is abstract. Always create one of its subclasses.
The AbstractMatplotlibViewer is the base class for the viewers that use the Matplotlib python plotting package.
Create a AbstractMatplotlibViewer.
- Parameters:
vars (CellVariable or list) – the Variable objects to display.
title (str, optional) – displayed at the top of the Viewer window
figaspect (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.
xmin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax. 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. 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. 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. 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. 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. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.
cmap (Colormap, optional) – the
Colormap
. Defaults to matplotlib.cm.jetcolorbar (bool, optional) – plot a color bar in specified orientation if not None
axes (Axes, optional) – if not None, vars will be plotted into this Matplotlib
Axes
objectlog (bool, optional) – whether to logarithmically scale the data
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property limits¶
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
fipy.viewers.matplotlibViewer.test module¶
Test numeric implementation of the mesh
Module contents¶
- class fipy.viewers.matplotlibViewer.Matplotlib1DViewer(vars, title=None, xlog=False, ylog=False, limits={}, legend='upper left', axes=None, **kwlimits)¶
Bases:
AbstractMatplotlibViewer
Displays a y vs. x plot of one or more 1D CellVariable objects using Matplotlib.
>>> import fipy as fp >>> mesh = fp.Grid1D(nx=100) >>> x, = mesh.cellCenters >>> xVar = fp.CellVariable(mesh=mesh, name="x", value=x) >>> k = fp.Variable(name="k", value=0.) >>> viewer = Matplotlib1DViewer(vars=(fp.numerix.sin(k * xVar) + 2, ... fp.numerix.cos(k * xVar / fp.numerix.pi) + 2), ... xmin=10, xmax=90, ... datamin=1.1, datamax=4.0, ... title="Matplotlib1DViewer test") >>> for kval in fp.numerix.arange(0, 0.3, 0.03): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer.cmap = "ocean" >>> viewer.log = True
>>> viewer.title = "Matplotlib1DViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
- Parameters:
vars (CellVariable or list) – CellVariable objects to plot
title (str, optional) – displayed at the top of the Viewer window
xlog (bool) – log scaling of x axis if True
ylog (bool) – log scaling of y axis if True
limits (dict) – a (deprecated) alternative to limit keyword arguments
xmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale. (ymin and ymax are synonyms for datamin and datamax).
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale. (ymin and ymax are synonyms for datamin and datamax).
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale. (ymin and ymax are synonyms for datamin and datamax).
datamax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale. (ymin and ymax are synonyms for datamin and datamax).
legend (str) – place a legend at the specified position, if not None
axes (Axes) – if not None, vars will be plotted into this Matplotlib
Axes
object
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property limits¶
- property lines¶
The collection of Matplotlib
Line2D
objects representing the plotted data.
- property log¶
Whether data has logarithmic scaling
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
- class fipy.viewers.matplotlibViewer.Matplotlib2DContourViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, number=None, levels=None, figaspect='auto', **kwlimits)¶
Bases:
AbstractMatplotlib2DViewer
Displays a contour plot of a 2D CellVariable object.
The Matplotlib2DContourViewer plots a 2D CellVariable using Matplotlib.
Creates a Matplotlib2DContourViewer.
- Parameters:
vars (CellVariable) – Variable to display
title (str, optional) – displayed at the top of the Viewer window
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
xmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
cmap (Colormap, optional) – the Colormap. Defaults to matplotlib.cm.jet
colorbar (bool, optional) – plot a color bar in specified orientation if not None
axes (Axes, optional) – if not None, vars will be plotted into this Matplotlib Axes object
number (int, optional) – Determines the number and positions of the contour lines / regions. (deprecated, use levels=).
levels (int or array-like, optional) – Determines the number and positions of the contour lines / regions. If an int n, tries to automatically choose no more than n+1 “nice” contour levels over the range of vars. If array-like, draw contour lines at the specified levels. The values must be in increasing order. E.g. to draw just the zero contour pass
levels=[0]
.figaspect (float) – 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.
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property levels¶
The number of automatically-chosen contours or their values.
- property limits¶
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
- class fipy.viewers.matplotlibViewer.Matplotlib2DGridContourViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, levels=None, figaspect='auto', **kwlimits)¶
Bases:
AbstractMatplotlib2DViewer
Displays a contour plot of a 2D CellVariable object.
The Matplotlib2DGridContourViewer plots a 2D CellVariable using Matplotlib.
>>> 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=0.) >>> viewer = Matplotlib2DGridContourViewer(vars=fp.numerix.sin(k * xyVar) * 1000 + 1002, ... ymin=0.1, ymax=0.9, ... # datamin=1.1, datamax=4.0, ... title="Matplotlib2DGridContourViewer test") >>> from builtins import range >>> for kval in range(10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer.levels = 2
>>> viewer.cmap = "ocean" >>> viewer.log = True
>>> viewer.title = "Matplotlib2DGridContourViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
Creates a Matplotlib2DViewer.
- Parameters:
vars (CellVariable) – the Variable to display.
title (str, optional) – displayed at the top of the Viewer window
limits (dict) – a (deprecated) alternative to limit keyword arguments
xmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
cmap (Colormap, optional) – the
Colormap
. Defaults to matplotlib.cm.jetcolorbar (bool, optional) – plot a color bar if not None
axes (Axes, optional) – if not None, vars will be plotted into this Matplotlib Axes object
levels (int or array-like, optional) – Determines the number and positions of the contour lines / regions. If an int n, tries to automatically choose no more than n+1 “nice” contour levels over the range of vars. If array-like, draw contour lines at the specified levels. The values must be in increasing order. E.g. to draw just the zero contour pass
levels=[0]
.figaspect (float, optional) – desired aspect ratio of figure. If a number, use that aspect ratio. If auto, the aspect ratio will be determined from the vars’s mesh.
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property levels¶
The number of automatically-chosen contours or their values.
- property limits¶
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
- class fipy.viewers.matplotlibViewer.Matplotlib2DGridViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)¶
Bases:
AbstractMatplotlib2DViewer
Displays an image plot of a 2D CellVariable object using Matplotlib.
>>> 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=0.) >>> viewer = Matplotlib2DGridViewer(vars=fp.numerix.sin(k * xyVar) * 1000 + 1002, ... ymin=0.1, ymax=0.9, ... # datamin=1.1, datamax=4.0, ... title="Matplotlib2DGridViewer 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 = "Matplotlib2DGridViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
Creates a Matplotlib2DGridViewer.
- Parameters:
vars (CellVariable) – the Variable to display.
title (str, optional) – displayed at the top of the Viewer window
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
cmap (Colormap, optional) – the
Colormap
. Defaults to matplotlib.cm.jetxmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
colorbar (bool, optional) – plot a color bar in specified orientation if not None
axes (Axes, optional) – if not None, vars will be plotted into this Matplotlib Axes object
figaspect (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.
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property limits¶
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
- class fipy.viewers.matplotlibViewer.Matplotlib2DViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)¶
Bases:
AbstractMatplotlib2DViewer
Displays a contour plot of a 2D CellVariable object.
The Matplotlib2DViewer plots a 2D CellVariable using Matplotlib.
>>> 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=0.) >>> viewer = Matplotlib2DViewer(vars=fp.numerix.sin(k * xyVar) * 1000 + 1002, ... ymin=0.1, ymax=0.9, ... # datamin=1.1, datamax=4.0, ... title="Matplotlib2DViewer 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 = "Matplotlib2DViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
Creates a Matplotlib2DViewer.
- Parameters:
vars (CellVariable) – the Variable to display.
title (str, optional) – displayed at the top of the Viewer window
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
cmap (Colormap, optional) – the
Colormap
. Defaults to matplotlib.cm.jetxmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
colorbar (bool, optional) – plot a color bar in specified orientation if not None
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.
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property collection¶
The Matplotlib
PolyCollection
representing the cells.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property limits¶
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
- class fipy.viewers.matplotlibViewer.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 or FaceVariable) – rank-1 Variable to display
title (str, optional) – displayed at the top of the Viewer window
log (bool, optional) – if True, arrow length goes at the base-10 logarithm of the magnitude
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
xmin (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 object
figaspect (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 or (float, float), optional) – Controls the closeness of streamlines. When
density = 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 or FaceVariable, 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 or CellVariable or FaceVariable, 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. If
None
, 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
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property kwargs¶
keyword arguments to pass to
streamplot()
.
- property limits¶
- 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 arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
- class fipy.viewers.matplotlibViewer.MatplotlibVectorViewer(vars, title=None, scale=None, sparsity=None, log=False, limits={}, axes=None, figaspect='auto', **kwlimits)¶
Bases:
AbstractMatplotlib2DViewer
Displays a vector plot of a 2D rank-1 CellVariable or FaceVariable object using Matplotlib
>>> 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 = MatplotlibVectorViewer(vars=fp.numerix.sin(k * xyVar).grad, ... title="MatplotlibVectorViewer test") >>> for kval in fp.numerix.arange(1, 10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=fp.numerix.sin(k * xyVar).faceGrad, ... title="MatplotlibVectorViewer test") >>> from builtins import range >>> for kval in range(10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> for sparsity in numerix.arange(5000, 0, -500): ... viewer.quiver(sparsity=sparsity) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer.cmap = "ocean" >>> viewer.log = True
>>> viewer.title = "MatplotlibVectorViewer 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 = MatplotlibVectorViewer(vars=fp.numerix.sin(k * xyVar).grad, ... title="MatplotlibVectorViewer test") >>> for kval in fp.numerix.arange(1, 10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=fp.numerix.sin(k * xyVar).faceGrad, ... title="MatplotlibVectorViewer test") >>> from builtins import range >>> for kval in range(10): ... k.setValue(kval) ... viewer.plot() >>> viewer._promptForOpinion()
>>> for sparsity in numerix.arange(5000, 0, -500): ... viewer.quiver(sparsity=sparsity) ... viewer.plot() >>> viewer._promptForOpinion()
>>> viewer.cmap = "ocean" >>> viewer.log = True
>>> viewer.title = "MatplotlibVectorViewer changed" >>> viewer.plot() >>> viewer._promptForOpinion()
Creates a Matplotlib2DViewer.
- Parameters:
vars (CellVariable or FaceVariable) – rank-1 Variable to display
title (str, optional) – displayed at the top of the Viewer window
scale (float, optional) – if not None, scale all arrow lengths by this value
sparsity (int, optional) – if not None, then this number of arrows will be randomly chosen (weighted by the cell volume or face area)
log (bool, optional) – if True, arrow length goes at the base-10 logarithm of the magnitude
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
xmin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
xmax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
ymax (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamin (float, optional) – displayed range of data. Any limit set to a (default) value of None will autoscale.
datamax (float, optional) – 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 object
figaspect (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.
- property axes¶
The Matplotlib
Axes
.
- property cmap¶
The Matplotlib
Colormap
.
- property colorbar¶
The Matplotlib
Colorbar
.
- property fig¶
The Matplotlib
Figure
.
- figaspect(figaspect, colorbar)¶
- property id¶
The Matplotlib
Figure
number.
- property limits¶
- 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.
- quiver(sparsity=None, scale=None)¶
- setLimits(limits={}, **kwlimits)¶
Update the limits.
- Parameters:
limits (dict, optional) – a (deprecated) alternative to limit keyword arguments
xmin (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.
- property title¶
The text appearing at the top center.
(default: if
len(self.vars) == 1
, the name ofself.vars[0]
, otherwise""
.)
- fipy.viewers.matplotlibViewer.MatplotlibViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, **kwlimits)¶
Generic function for creating a MatplotlibViewer.
The MatplotlibViewer factory will search the module tree and return an instance of the first MatplotlibViewer it finds of the correct dimension and rank.
It is possible to view different
Variable
s against different Matplotlib Axes>>> from matplotlib import pyplot as plt >>> from fipy import *
>>> plt.ion() >>> fig = plt.figure()
>>> ax1 = plt.subplot((221)) >>> ax2 = plt.subplot((223)) >>> ax3 = plt.subplot((224))
>>> k = Variable(name="k", value=0.)
>>> mesh1 = Grid1D(nx=100) >>> x, = mesh1.cellCenters >>> xVar = CellVariable(mesh=mesh1, name="x", value=x) >>> viewer1 = MatplotlibViewer(vars=(numerix.sin(0.1 * k * xVar), numerix.cos(0.1 * k * xVar / numerix.pi)), ... limits={'xmin': 10, 'xmax': 90}, ... datamin=-0.9, datamax=2.0, ... title="Grid1D test", ... axes=ax1, ... legend=None)
>>> mesh2 = Grid2D(nx=50, ny=100, dx=0.1, dy=0.01) >>> x, y = mesh2.cellCenters >>> xyVar = CellVariable(mesh=mesh2, name="x y", value=x * y) >>> viewer2 = MatplotlibViewer(vars=numerix.sin(k * xyVar), ... limits={'ymin': 0.1, 'ymax': 0.9}, ... datamin=-0.9, datamax=2.0, ... title="Grid2D test", ... axes=ax2, ... colorbar=None)
>>> mesh3 = (Grid2D(nx=5, ny=10, dx=0.1, dy=0.1) ... + (Tri2D(nx=5, ny=5, dx=0.1, dy=0.1) ... + ((0.5,), (0.2,)))) >>> x, y = mesh3.cellCenters >>> xyVar = CellVariable(mesh=mesh3, name="x y", value=x * y) >>> viewer3 = MatplotlibViewer(vars=numerix.sin(k * xyVar), ... limits={'ymin': 0.1, 'ymax': 0.9}, ... datamin=-0.9, datamax=2.0, ... title="Irregular 2D test", ... axes=ax3, ... cmap = plt.cm.OrRd)
>>> viewer = MultiViewer(viewers=(viewer1, viewer2, viewer3)) >>> from builtins import range >>> for kval in range(10): ... k.setValue(kval) ... viewer.plot()
>>> viewer._promptForOpinion()
- Parameters:
vars (CellVariable or list) – the Variable objects to display.
title (str, optional) – displayed at the top of the Viewer window
limits (dict) – a (deprecated) alternative to limit keyword arguments
xmin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax. 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. 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. 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. 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. 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. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.
cmap (Colormap, optional) – the
Colormap
. Defaults to matplotlib.cm.jetcolorbar (bool, optional) – plot a color bar in specified orientation if not None
axes (Axes, optional) – if not None, vars will be plotted into this Matplotlib Axes object