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: fipy.viewers.matplotlibViewer.matplotlibViewer.AbstractMatplotlibViewer

Displays a y vs. x plot of one or more 1D CellVariable objects using Matplotlib.

>>> from fipy import *
>>> mesh = Grid1D(nx=100)
>>> x, = mesh.cellCenters
>>> xVar = CellVariable(mesh=mesh, name="x", value=x)
>>> k = Variable(name="k", value=0.)
>>> viewer = Matplotlib1DViewer(vars=(numerix.sin(k * xVar), numerix.cos(k * xVar / numerix.pi)),
...                 limits={'xmin': 10, 'xmax': 90},
...                 datamin=-0.9, datamax=2.0,
...                 title="Matplotlib1DViewer test")
>>> for kval in numerix.arange(0, 0.3, 0.03):
...     k.setValue(kval)
...     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) – 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

__annotations__ = {}
__init__(vars, title=None, xlog=False, ylog=False, limits={}, legend='upper left', axes=None, **kwlimits)
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) – 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

__module__ = 'fipy.viewers.matplotlibViewer.matplotlib1DViewer'
property log

logarithmic data scaling

fipy.viewers.matplotlibViewer.matplotlib2DContourViewer module

class fipy.viewers.matplotlibViewer.matplotlib2DContourViewer.Matplotlib2DContourViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, number=10, levels=None, figaspect='auto', **kwlimits)

Bases: fipy.viewers.matplotlibViewer.matplotlib2DViewer.AbstractMatplotlib2DViewer

Displays a contour plot of a 2D CellVariable object.

The Matplotlib2DContourViewer plots a 2D CellVariable using Matplotlib.

>>> from fipy import *
>>> mesh = Grid2D(nx=50, ny=100, dx=0.1, dy=0.01)
>>> x, y = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=0.)
>>> viewer = Matplotlib2DContourViewer(vars=numerix.sin(k * xyVar),
...                 limits={'ymin': 0.1, 'ymax': 0.9},
...                 datamin=-0.9, datamax=2.0,
...                 title="Matplotlib2DContourViewer test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()

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) – 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) – contour number automatically-chosen levels

  • levels (list of float, optional) – A list of numbers indicating the level curves to draw; 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.

__init__(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, number=10, levels=None, figaspect='auto', **kwlimits)

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) – 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) – contour number automatically-chosen levels

  • levels (list of float, optional) – A list of numbers indicating the level curves to draw; 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.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlib2DContourViewer'

fipy.viewers.matplotlibViewer.matplotlib2DGridContourViewer module

class fipy.viewers.matplotlibViewer.matplotlib2DGridContourViewer.Matplotlib2DGridContourViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)

Bases: fipy.viewers.matplotlibViewer.matplotlib2DViewer.AbstractMatplotlib2DViewer

Displays a contour plot of a 2D CellVariable object.

The Matplotlib2DGridContourViewer plots a 2D CellVariable using Matplotlib.

>>> from fipy import *
>>> mesh = Grid2D(nx=50, ny=100, dx=0.1, dy=0.01)
>>> x, y = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=0.)
>>> viewer = Matplotlib2DGridContourViewer(vars=numerix.sin(k * xyVar),
...                 limits={'ymin': 0.1, 'ymax': 0.9},
...                 datamin=-0.9, datamax=2.0,
...                 title="Matplotlib2DGridContourViewer test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     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) – 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 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 a number, use that aspect ratio. If auto, the aspect ratio will be determined from the vars’s mesh.

__annotations__ = {}
__init__(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)

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) – 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 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 a number, use that aspect ratio. If auto, the aspect ratio will be determined from the vars’s mesh.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlib2DGridContourViewer'

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: fipy.viewers.matplotlibViewer.matplotlib2DViewer.AbstractMatplotlib2DViewer

Displays an image plot of a 2D CellVariable object using Matplotlib.

>>> from fipy import *
>>> mesh = Grid2D(nx=50, ny=100, dx=0.1, dy=0.01)
>>> x, y = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=0.)
>>> viewer = Matplotlib2DGridViewer(vars=numerix.sin(k * xyVar),
...                 limits={'ymin': 0.1, 'ymax': 0.9},
...                 datamin=-0.9, datamax=2.0,
...                 title="Matplotlib2DGridViewer test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     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.jet

  • xmin (float) – 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.

__annotations__ = {}
__init__(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)

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.jet

  • xmin (float) – 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.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlib2DGridViewer'

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: fipy.viewers.matplotlibViewer.matplotlib2DViewer.AbstractMatplotlib2DViewer

Displays a contour plot of a 2D CellVariable object.

The Matplotlib2DViewer plots a 2D CellVariable using Matplotlib.

>>> from fipy import *
>>> mesh = (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 = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=0.)
>>> viewer = Matplotlib2DViewer(vars=numerix.sin(k * xyVar),
...                 limits={'ymin': 0.1, 'ymax': 0.9},
...                 datamin=-0.9, datamax=2.0,
...                 title="Matplotlib2DViewer test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     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.jet

  • xmin (float) – 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.

__annotations__ = {}
__init__(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)

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.jet

  • xmin (float) – 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.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlib2DViewer'

fipy.viewers.matplotlibViewer.matplotlibSparseMatrixViewer module

class fipy.viewers.matplotlibViewer.matplotlibSparseMatrixViewer.MatplotlibSparseMatrixViewer(title='Sparsity')

Bases: object

__dict__ = mappingproxy({'__module__': 'fipy.viewers.matplotlibViewer.matplotlibSparseMatrixViewer', '__init__': <function MatplotlibSparseMatrixViewer.__init__>, 'plot': <function MatplotlibSparseMatrixViewer.plot>, '__dict__': <attribute '__dict__' of 'MatplotlibSparseMatrixViewer' objects>, '__weakref__': <attribute '__weakref__' of 'MatplotlibSparseMatrixViewer' objects>, '__doc__': None, '__annotations__': {}})
__init__(title='Sparsity')

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlibSparseMatrixViewer'
__weakref__

list of weak references to the object (if defined)

plot(matrix, RHSvector, log='auto')

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: fipy.viewers.matplotlibViewer.matplotlib2DViewer.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.

>>> from fipy import *
>>> mesh = Grid2D(nx=50, ny=100, dx=0.1, dy=0.01)
>>> x, y = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=1.)
>>> viewer = MatplotlibStreamViewer(vars=numerix.sin(k * xyVar).grad,
...                 title="MatplotlibStreamViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibStreamViewer(vars=numerix.sin(k * xyVar).faceGrad,
...                 title="MatplotlibStreamViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> from fipy import *
>>> mesh = (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 = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=1.)
>>> viewer = MatplotlibStreamViewer(vars=numerix.sin(k * xyVar).grad,
...                 title="MatplotlibStreamViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibStreamViewer(vars=numerix.sin(k * xyVar).faceGrad,
...                 title="MatplotlibStreamViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     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.

__annotations__ = {}
__init__(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)

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.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlibStreamViewer'

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: fipy.viewers.matplotlibViewer.matplotlib2DViewer.AbstractMatplotlib2DViewer

Displays a vector plot of a 2D rank-1 CellVariable or FaceVariable object using Matplotlib

>>> from fipy import *
>>> mesh = Grid2D(nx=50, ny=100, dx=0.1, dy=0.01)
>>> x, y = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=1.)
>>> viewer = MatplotlibVectorViewer(vars=numerix.sin(k * xyVar).grad,
...                 title="MatplotlibVectorViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=numerix.sin(k * xyVar).faceGrad,
...                 title="MatplotlibVectorViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> for sparsity in numerix.arange(5000, 0, -500):
...     viewer.quiver(sparsity=sparsity)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> from fipy import *
>>> mesh = (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 = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=1.)
>>> viewer = MatplotlibVectorViewer(vars=numerix.sin(k * xyVar).grad,
...                 title="MatplotlibVectorViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=numerix.sin(k * xyVar).faceGrad,
...                 title="MatplotlibVectorViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     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) – 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.

__annotations__ = {}
__init__(vars, title=None, scale=None, sparsity=None, log=False, limits={}, axes=None, figaspect='auto', **kwlimits)

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) – 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.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlibVectorViewer'
quiver(sparsity=None, scale=None)

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: fipy.viewers.viewer.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) – 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.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

  • log (bool, optional) – whether to logarithmically scale the data

__init__(vars, title=None, figaspect=1.0, cmap=None, colorbar=None, axes=None, log=False, **kwlimits)

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) – 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.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

  • log (bool, optional) – whether to logarithmically scale the data

__module__ = 'fipy.viewers.matplotlibViewer.matplotlibViewer'
figaspect(figaspect, colorbar)
property log

logarithmic data scaling

property mappable
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.

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: fipy.viewers.matplotlibViewer.matplotlibViewer.AbstractMatplotlibViewer

Displays a y vs. x plot of one or more 1D CellVariable objects using Matplotlib.

>>> from fipy import *
>>> mesh = Grid1D(nx=100)
>>> x, = mesh.cellCenters
>>> xVar = CellVariable(mesh=mesh, name="x", value=x)
>>> k = Variable(name="k", value=0.)
>>> viewer = Matplotlib1DViewer(vars=(numerix.sin(k * xVar), numerix.cos(k * xVar / numerix.pi)),
...                 limits={'xmin': 10, 'xmax': 90},
...                 datamin=-0.9, datamax=2.0,
...                 title="Matplotlib1DViewer test")
>>> for kval in numerix.arange(0, 0.3, 0.03):
...     k.setValue(kval)
...     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) – 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

__annotations__ = {}
__init__(vars, title=None, xlog=False, ylog=False, limits={}, legend='upper left', axes=None, **kwlimits)
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) – 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

__module__ = 'fipy.viewers.matplotlibViewer.matplotlib1DViewer'
property log

logarithmic data scaling

class fipy.viewers.matplotlibViewer.Matplotlib2DGridContourViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)

Bases: fipy.viewers.matplotlibViewer.matplotlib2DViewer.AbstractMatplotlib2DViewer

Displays a contour plot of a 2D CellVariable object.

The Matplotlib2DGridContourViewer plots a 2D CellVariable using Matplotlib.

>>> from fipy import *
>>> mesh = Grid2D(nx=50, ny=100, dx=0.1, dy=0.01)
>>> x, y = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=0.)
>>> viewer = Matplotlib2DGridContourViewer(vars=numerix.sin(k * xyVar),
...                 limits={'ymin': 0.1, 'ymax': 0.9},
...                 datamin=-0.9, datamax=2.0,
...                 title="Matplotlib2DGridContourViewer test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     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) – 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 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 a number, use that aspect ratio. If auto, the aspect ratio will be determined from the vars’s mesh.

__annotations__ = {}
__init__(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)

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) – 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 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 a number, use that aspect ratio. If auto, the aspect ratio will be determined from the vars’s mesh.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlib2DGridContourViewer'
class fipy.viewers.matplotlibViewer.Matplotlib2DGridViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)

Bases: fipy.viewers.matplotlibViewer.matplotlib2DViewer.AbstractMatplotlib2DViewer

Displays an image plot of a 2D CellVariable object using Matplotlib.

>>> from fipy import *
>>> mesh = Grid2D(nx=50, ny=100, dx=0.1, dy=0.01)
>>> x, y = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=0.)
>>> viewer = Matplotlib2DGridViewer(vars=numerix.sin(k * xyVar),
...                 limits={'ymin': 0.1, 'ymax': 0.9},
...                 datamin=-0.9, datamax=2.0,
...                 title="Matplotlib2DGridViewer test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     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.jet

  • xmin (float) – 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.

__annotations__ = {}
__init__(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)

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.jet

  • xmin (float) – 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.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlib2DGridViewer'
class fipy.viewers.matplotlibViewer.Matplotlib2DViewer(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)

Bases: fipy.viewers.matplotlibViewer.matplotlib2DViewer.AbstractMatplotlib2DViewer

Displays a contour plot of a 2D CellVariable object.

The Matplotlib2DViewer plots a 2D CellVariable using Matplotlib.

>>> from fipy import *
>>> mesh = (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 = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=0.)
>>> viewer = Matplotlib2DViewer(vars=numerix.sin(k * xyVar),
...                 limits={'ymin': 0.1, 'ymax': 0.9},
...                 datamin=-0.9, datamax=2.0,
...                 title="Matplotlib2DViewer test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     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.jet

  • xmin (float) – 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.

__annotations__ = {}
__init__(vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits)

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.jet

  • xmin (float) – 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.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlib2DViewer'
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: fipy.viewers.matplotlibViewer.matplotlib2DViewer.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.

>>> from fipy import *
>>> mesh = Grid2D(nx=50, ny=100, dx=0.1, dy=0.01)
>>> x, y = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=1.)
>>> viewer = MatplotlibStreamViewer(vars=numerix.sin(k * xyVar).grad,
...                 title="MatplotlibStreamViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibStreamViewer(vars=numerix.sin(k * xyVar).faceGrad,
...                 title="MatplotlibStreamViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> from fipy import *
>>> mesh = (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 = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=1.)
>>> viewer = MatplotlibStreamViewer(vars=numerix.sin(k * xyVar).grad,
...                 title="MatplotlibStreamViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibStreamViewer(vars=numerix.sin(k * xyVar).faceGrad,
...                 title="MatplotlibStreamViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     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.

__annotations__ = {}
__init__(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)

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.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlibStreamViewer'
class fipy.viewers.matplotlibViewer.MatplotlibVectorViewer(vars, title=None, scale=None, sparsity=None, log=False, limits={}, axes=None, figaspect='auto', **kwlimits)

Bases: fipy.viewers.matplotlibViewer.matplotlib2DViewer.AbstractMatplotlib2DViewer

Displays a vector plot of a 2D rank-1 CellVariable or FaceVariable object using Matplotlib

>>> from fipy import *
>>> mesh = Grid2D(nx=50, ny=100, dx=0.1, dy=0.01)
>>> x, y = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=1.)
>>> viewer = MatplotlibVectorViewer(vars=numerix.sin(k * xyVar).grad,
...                 title="MatplotlibVectorViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=numerix.sin(k * xyVar).faceGrad,
...                 title="MatplotlibVectorViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> for sparsity in numerix.arange(5000, 0, -500):
...     viewer.quiver(sparsity=sparsity)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> from fipy import *
>>> mesh = (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 = mesh.cellCenters
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=1.)
>>> viewer = MatplotlibVectorViewer(vars=numerix.sin(k * xyVar).grad,
...                 title="MatplotlibVectorViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=numerix.sin(k * xyVar).faceGrad,
...                 title="MatplotlibVectorViewer test")
>>> for kval in numerix.arange(1, 10):
...     k.setValue(kval)
...     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) – 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.

__annotations__ = {}
__init__(vars, title=None, scale=None, sparsity=None, log=False, limits={}, axes=None, figaspect='auto', **kwlimits)

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) – 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.

__module__ = 'fipy.viewers.matplotlibViewer.matplotlibVectorViewer'
quiver(sparsity=None, scale=None)
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 Variables 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) – 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.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

Last updated on Jan 14, 2021. Created using Sphinx 3.4.3.