Bookmark and Share FiPy: A Finite Volume PDE Solver Using Python
Version 2.1.3

This Page

Contact

FiPy developers
Jonathan Guyer
Daniel Wheeler
James Warren

Join our mailing list

100 Bureau Drive, M/S 6555
Gaithersburg, MD 20899

301-975-5329 Telephone
301-975-4553 Facsimile

matplotlibViewer Package Documentation

This page contains the matplotlibViewer Package documentation.

The matplotlibViewer Package

fipy.viewers.matplotlibViewer.MatplotlibViewer(vars, title=None, limits={}, cmap=None, colorbar=None, 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.

Parameters :
vars

a CellVariable or tuple of CellVariable objects to plot

title

displayed at the top of the Viewer window

limits : dict

a (deprecated) alternative to limit keyword arguments

xmin, xmax, ymin, ymax, datamin, datamax

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

the colormap. Defaults to matplotlib.cm.jet

colorbar

plot a colorbar in specified orientation if not None

axes

if not None, vars will be plotted into this Matplotlib Axes object

It is possible to view different Variable`s against different Matplotlib_ `Axes

>>> from matplotlib import pylab
>>> from fipy import *
>>> fig = pylab.figure()
>>> ax1 = pylab.subplot((221))
>>> ax2 = pylab.subplot((223))
>>> ax3 = pylab.subplot((224))
>>> k = Variable(name="k", value=0.)
>>> mesh1 = Grid1D(nx=100)
>>> x, = mesh1.getCellCenters()
>>> xVar = CellVariable(mesh=mesh1, name="x", value=x)
>>> viewer1 = MatplotlibViewer(vars=(sin(0.1 * k * xVar), cos(0.1 * k * xVar / 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.getCellCenters()
>>> xyVar = CellVariable(mesh=mesh2, name="x y", value=x * y)
>>> viewer2 = MatplotlibViewer(vars=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.getCellCenters()
>>> xyVar = CellVariable(mesh=mesh3, name="x y", value=x * y)
>>> viewer3 = MatplotlibViewer(vars=sin(k * xyVar), 
...                            limits={'ymin': 0.1, 'ymax': 0.9}, 
...                            datamin=-0.9, datamax=2.0,
...                            title="Irregular 2D test",
...                            axes=ax3,
...                            cmap = pylab.cm.OrRd)
>>> viewer = MultiViewer(viewers=(viewer1, viewer2, viewer3))
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
class fipy.viewers.matplotlibViewer.Matplotlib1DViewer(vars, title=None, xlog=False, ylog=False, limits={}, legend='upper left', axes=None, **kwlimits)

Bases: fipy.viewers.matplotlibViewer.matplotlibViewer._MatplotlibViewer

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

>>> from fipy import *
>>> mesh = Grid1D(nx=100)
>>> x, = mesh.getCellCenters()
>>> xVar = CellVariable(mesh=mesh, name="x", value=x)
>>> k = Variable(name="k", value=0.)
>>> viewer = Matplotlib1DViewer(vars=(sin(k * xVar), cos(k * xVar / 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

a CellVariable or tuple of CellVariable objects to plot

title

displayed at the top of the Viewer window

xlog

log scaling of x axis if True

ylog

log scaling of y axis if True

limits : dict

a (deprecated) alternative to limit keyword arguments

xmin, xmax, datamin, datamax

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

place a legend at the specified position, if not None

axes

if not None, vars will be plotted into this Matplotlib Axes object

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

Bases: fipy.viewers.matplotlibViewer.matplotlibViewer._MatplotlibViewer

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

Creates a Matplotlib2DGridViewer.

Parameters :
vars

A CellVariable object.

title

displayed at the top of the Viewer window

limits : dict

a (deprecated) alternative to limit keyword arguments

cmap

The colormap. Defaults to matplotlib.cm.jet

xmin, xmax, ymin, ymax, datamin, datamax

displayed range of data. Any limit set to a (default) value of None will autoscale.

colorbar

plot a colorbar in specified orientation if not None

axes

if not None, vars will be plotted into this Matplotlib Axes object

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

Bases: fipy.viewers.matplotlibViewer.matplotlibViewer._MatplotlibViewer

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

Creates a Matplotlib2DViewer.

Parameters :
vars

a CellVariable object.

title

displayed at the top of the Viewer window

limits : dict

a (deprecated) alternative to limit keyword arguments

xmin, xmax, ymin, ymax, datamin, datamax

displayed range of data. Any limit set to a (default) value of None will autoscale.

cmap

the colormap. Defaults to matplotlib.cm.jet

colorbar

plot a colorbar in specified orientation if not None

axes

if not None, vars will be plotted into this Matplotlib Axes object

class fipy.viewers.matplotlibViewer.Matplotlib2DViewer(vars, title=None, limits={}, cmap=None, colorbar=True, axes=None, **kwlimits)

Bases: fipy.viewers.matplotlibViewer.matplotlibViewer._MatplotlibViewer

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

Creates a Matplotlib2DViewer.

Parameters :
vars

a CellVariable object.

title

displayed at the top of the Viewer window

limits : dict

a (deprecated) alternative to limit keyword arguments

cmap

the colormap. Defaults to matplotlib.cm.jet

xmin, xmax, ymin, ymax, datamin, datamax

displayed range of data. Any limit set to a (default) value of None will autoscale.

colorbar

plot a colorbar in specified orientation if not None

axes

if not None, vars will be plotted into this Matplotlib Axes object

class fipy.viewers.matplotlibViewer.MatplotlibVectorViewer(vars, title=None, scale=None, sparsity=None, limits={}, axes=None, **kwlimits)

Bases: fipy.viewers.matplotlibViewer.matplotlibViewer._MatplotlibViewer

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.getCellCenters()
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=0.)
>>> viewer = MatplotlibVectorViewer(vars=sin(k * xyVar).getGrad(), 
...                 title="MatplotlibVectorViewer test")
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=sin(k * xyVar).getFaceGrad(), 
...                 title="MatplotlibVectorViewer test")
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> for sparsity in 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.getCellCenters()
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=0.)
>>> viewer = MatplotlibVectorViewer(vars=sin(k * xyVar).getGrad(), 
...                 title="MatplotlibVectorViewer test")
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=sin(k * xyVar).getFaceGrad(), 
...                 title="MatplotlibVectorViewer test")
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()

Creates a Matplotlib2DViewer.

Parameters :
vars

a rank-1 CellVariable or FaceVariable object.

title

displayed at the top of the Viewer window

scale

if not None, scale all arrow lengths by this value

sparsity

if not None, then this number of arrows will be randomly chosen (weighted by the cell volume or face area)

limits : dict

a (deprecated) alternative to limit keyword arguments

xmin, xmax, ymin, ymax, datamin, datamax

displayed range of data. Any limit set to a (default) value of None will autoscale.

axes

if not None, vars will be plotted into this Matplotlib Axes object

quiver(sparsity=None, scale=None)

The 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._MatplotlibViewer

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

>>> from fipy import *
>>> mesh = Grid1D(nx=100)
>>> x, = mesh.getCellCenters()
>>> xVar = CellVariable(mesh=mesh, name="x", value=x)
>>> k = Variable(name="k", value=0.)
>>> viewer = Matplotlib1DViewer(vars=(sin(k * xVar), cos(k * xVar / 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

a CellVariable or tuple of CellVariable objects to plot

title

displayed at the top of the Viewer window

xlog

log scaling of x axis if True

ylog

log scaling of y axis if True

limits : dict

a (deprecated) alternative to limit keyword arguments

xmin, xmax, datamin, datamax

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

place a legend at the specified position, if not None

axes

if not None, vars will be plotted into this Matplotlib Axes object

The matplotlib2DGridContourViewer Module

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

Bases: fipy.viewers.matplotlibViewer.matplotlibViewer._MatplotlibViewer

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

Creates a Matplotlib2DViewer.

Parameters :
vars

a CellVariable object.

title

displayed at the top of the Viewer window

limits : dict

a (deprecated) alternative to limit keyword arguments

xmin, xmax, ymin, ymax, datamin, datamax

displayed range of data. Any limit set to a (default) value of None will autoscale.

cmap

the colormap. Defaults to matplotlib.cm.jet

colorbar

plot a colorbar in specified orientation if not None

axes

if not None, vars will be plotted into this Matplotlib Axes object

The matplotlib2DGridViewer Module

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

Bases: fipy.viewers.matplotlibViewer.matplotlibViewer._MatplotlibViewer

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

Creates a Matplotlib2DGridViewer.

Parameters :
vars

A CellVariable object.

title

displayed at the top of the Viewer window

limits : dict

a (deprecated) alternative to limit keyword arguments

cmap

The colormap. Defaults to matplotlib.cm.jet

xmin, xmax, ymin, ymax, datamin, datamax

displayed range of data. Any limit set to a (default) value of None will autoscale.

colorbar

plot a colorbar in specified orientation if not None

axes

if not None, vars will be plotted into this Matplotlib Axes object

The matplotlib2DViewer Module

class fipy.viewers.matplotlibViewer.matplotlib2DViewer.Matplotlib2DViewer(vars, title=None, limits={}, cmap=None, colorbar=True, axes=None, **kwlimits)

Bases: fipy.viewers.matplotlibViewer.matplotlibViewer._MatplotlibViewer

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

Creates a Matplotlib2DViewer.

Parameters :
vars

a CellVariable object.

title

displayed at the top of the Viewer window

limits : dict

a (deprecated) alternative to limit keyword arguments

cmap

the colormap. Defaults to matplotlib.cm.jet

xmin, xmax, ymin, ymax, datamin, datamax

displayed range of data. Any limit set to a (default) value of None will autoscale.

colorbar

plot a colorbar in specified orientation if not None

axes

if not None, vars will be plotted into this Matplotlib Axes object

The matplotlibSparseMatrixViewer Module

class fipy.viewers.matplotlibViewer.matplotlibSparseMatrixViewer.MatplotlibSparseMatrixViewer(title='Sparsity')
plot(matrix, RHSvector, log='auto')
class fipy.viewers.matplotlibViewer.matplotlibSparseMatrixViewer.SignedLogFormatter(base=10.0, labelOnlyBase=True, threshold=0.0)

Bases: matplotlib.ticker.LogFormatter

Format values for log axis;

if attribute decadeOnly is True, only the decades will be labelled.

base is used to locate the decade tick, which will be the only one to be labeled if labelOnlyBase is False

pprint_val(x, d)
class fipy.viewers.matplotlibViewer.matplotlibSparseMatrixViewer.SignedLogLocator(base=10.0, subs=[1.0], threshold=0.0)

Bases: matplotlib.ticker.LogLocator

Determine the tick locations for “log” axes that express both positive and negative values

place ticks on the location= base**i*subs[j]

autoscale()

Try to choose the view limits intelligently

The matplotlibVectorViewer Module

class fipy.viewers.matplotlibViewer.matplotlibVectorViewer.MatplotlibVectorViewer(vars, title=None, scale=None, sparsity=None, limits={}, axes=None, **kwlimits)

Bases: fipy.viewers.matplotlibViewer.matplotlibViewer._MatplotlibViewer

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.getCellCenters()
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=0.)
>>> viewer = MatplotlibVectorViewer(vars=sin(k * xyVar).getGrad(), 
...                 title="MatplotlibVectorViewer test")
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=sin(k * xyVar).getFaceGrad(), 
...                 title="MatplotlibVectorViewer test")
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> for sparsity in 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.getCellCenters()
>>> xyVar = CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = Variable(name="k", value=0.)
>>> viewer = MatplotlibVectorViewer(vars=sin(k * xyVar).getGrad(), 
...                 title="MatplotlibVectorViewer test")
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> viewer = MatplotlibVectorViewer(vars=sin(k * xyVar).getFaceGrad(), 
...                 title="MatplotlibVectorViewer test")
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()

Creates a Matplotlib2DViewer.

Parameters :
vars

a rank-1 CellVariable or FaceVariable object.

title

displayed at the top of the Viewer window

scale

if not None, scale all arrow lengths by this value

sparsity

if not None, then this number of arrows will be randomly chosen (weighted by the cell volume or face area)

limits : dict

a (deprecated) alternative to limit keyword arguments

xmin, xmax, ymin, ymax, datamin, datamax

displayed range of data. Any limit set to a (default) value of None will autoscale.

axes

if not None, vars will be plotted into this Matplotlib Axes object

quiver(sparsity=None, scale=None)

The matplotlibViewer Module

The test Module

Test numeric implementation of the mesh