def __init__(self, vars, title=None, xlog=False, ylog=False, limits={}, legend='upper left', axes=None, **kwlimits): """ :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 """ kwlimits.update(limits) AbstractMatplotlibViewer.__init__(self, vars=vars, title=title, axes=axes, **kwlimits) import pylab if xlog and ylog: self.lines = [self.axes.loglog(*datum) for datum in self._data] elif xlog: self.lines = [self.axes.semilogx(*datum) for datum in self._data] elif ylog: self.lines = [self.axes.semilogy(*datum) for datum in self._data] else: self.lines = [self.axes.plot(*datum) for datum in self._data] if legend is not None: self.axes.legend([var.name for var in self.vars], loc=legend) self.axes.set_xlim(xmin=self._getLimit('xmin'), xmax=self._getLimit('xmax')) ymin = self._getLimit(('datamin', 'ymin')) ymax = self._getLimit(('datamax', 'ymax')) self.axes.set_ylim(ymin=ymin, ymax=ymax) if ymax is None or ymin is None: import warnings warnings.warn("Matplotlib1DViewer efficiency is improved by setting the 'datamax' and 'datamin' keys", UserWarning, stacklevel=2)
def __init__(self, phase, potential, components, charge, potentials, limits=None): AbstractMatplotlibViewer.__init__(self, vars=[phase] + components + [potential, charge], limits=limits) self.phase = phase self.potential = potential self.components = components self.charge = charge pylab.ioff() pylab.subplot(511) self.lines = [pylab.plot(*datum) for datum in self._getData([phase])] pylab.ylim(ymin=0., ymax=1.) pylab.xlim(xmin = self._getLimit('xmin'), xmax = self._getLimit('xmax')) pylab.ylabel(r'$\xi$') pylab.subplot(512) # self.lines += [pylab.plot(*datum) for datum in self._getData(self.components)] self.lines += [pylab.semilogy(*datum) for datum in self._getData(self.components)] pylab.legend([var.name for var in self.components]) pylab.xlim(xmin = self._getLimit('xmin'), xmax = self._getLimit('xmax')) pylab.ylabel(r'$\bar{V}_S C_j$') pylab.subplot(513) self.lines += [pylab.plot(*datum) for datum in self._getData([potential])] pylab.ylabel(r'$\phi\cal{F} / R T$') pylab.xlim(xmin = self._getLimit('xmin'), xmax = self._getLimit('xmax')) pylab.subplot(514) self.lines += [pylab.plot(*datum) for datum in self._getData([charge])] pylab.xlim(xmin = self._getLimit('xmin'), xmax = self._getLimit('xmax')) pylab.ylabel(r'$\bar{V}_S \sum_j z_j C_j$') pylab.subplot(515) self.chemicalPotentials = potentials # [var.muBar for var in potentials] # + [self.phase] self.lines += [pylab.plot(*datum) for datum in self._getData(self.chemicalPotentials)] pylab.legend([var.name for var in potentials]) # + [self.phase] pylab.xlim(xmin = self._getLimit('xmin'), xmax = self._getLimit('xmax')) pylab.ylabel(r'$\bar{\mu}_j / R T$') pylab.xlabel(r'$x/L$') pylab.draw() pylab.ion()
def __init__(self, vars, title=None, xlog=False, ylog=False, limits={}, legend='upper left', axes=None, **kwlimits): """ :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 """ kwlimits.update(limits) AbstractMatplotlibViewer.__init__(self, vars=vars, title=title, axes=axes, **kwlimits) if xlog and ylog: self.lines = [self.axes.loglog(*datum) for datum in self._data] elif xlog: self.lines = [self.axes.semilogx(*datum) for datum in self._data] elif ylog: self.lines = [self.axes.semilogy(*datum) for datum in self._data] else: self.lines = [self.axes.plot(*datum) for datum in self._data] if legend is not None: self.axes.legend([var.name for var in self.vars], loc=legend) self.axes.set_xlim(xmin=self._getLimit('xmin'), xmax=self._getLimit('xmax')) ymin = self._getLimit(('datamin', 'ymin')) ymax = self._getLimit(('datamax', 'ymax')) self.axes.set_ylim(ymin=ymin, ymax=ymax) if ymax is None or ymin is None: import warnings warnings.warn("Matplotlib1DViewer efficiency is improved by setting the 'datamax' and 'datamin' keys", UserWarning, stacklevel=2)
def __init__(self, distanceVar, surfactantVar=None, levelSetValue=0., title=None, smooth=0, zoomFactor=1., animate=False, limits={}, **kwlimits): """ Create a `MatplotlibSurfactantViewer`. >>> from fipy import * >>> m = Grid2D(nx=100, ny=100) >>> x, y = m.cellCenters >>> v = CellVariable(mesh=m, value=x**2 + y**2 - 10**2) >>> s = CellVariable(mesh=m, value=sin(x / 10) * cos(y / 30)) >>> viewer = MatplotlibSurfactantViewer(distanceVar=v, surfactantVar=s) >>> for r in range(1,200): ... v.setValue(x**2 + y**2 - r**2) ... viewer.plot() >>> from fipy import * >>> dx = 1. >>> dy = 1. >>> nx = 11 >>> ny = 11 >>> Lx = ny * dy >>> Ly = nx * dx >>> mesh = Grid2D(dx = dx, dy = dy, nx = nx, ny = ny) >>> # from fipy.models.levelSet.distanceFunction.distanceVariable import DistanceVariable >>> var = DistanceVariable(mesh = mesh, value = -1) >>> x, y = mesh.cellCenters >>> var.setValue(1, where=(x - Lx / 2.)**2 + (y - Ly / 2.)**2 < (Lx / 4.)**2) >>> var.calcDistanceFunction() >>> viewer = MatplotlibSurfactantViewer(var, smooth = 2) >>> viewer.plot() >>> viewer._promptForOpinion() >>> del viewer >>> var = DistanceVariable(mesh = mesh, value = -1) >>> var.setValue(1, where=(y > 2. * Ly / 3.) | ((x > Lx / 2.) & (y > Ly / 3.)) | ((y < Ly / 6.) & (x > Lx / 2))) >>> var.calcDistanceFunction() >>> viewer = MatplotlibSurfactantViewer(var) >>> viewer.plot() >>> viewer._promptForOpinion() >>> del viewer >>> viewer = MatplotlibSurfactantViewer(var, smooth = 2) >>> viewer.plot() >>> viewer._promptForOpinion() >>> del viewer :Parameters: - `distanceVar`: a `DistanceVariable` object. - `levelSetValue`: the value of the contour to be displayed - `title`: displayed at the top of the `Viewer` window - `animate`: whether to show only the initial condition and the - `limits`: a dictionary with possible keys `xmin`, `xmax`, `ymin`, `ymax`, `zmin`, `zmax`, `datamin`, `datamax`. A 1D `Viewer` will only use `xmin` and `xmax`, a 2D viewer will also use `ymin` and `ymax`, and so on. All viewers will use `datamin` and `datamax`. Any limit set to a (default) value of `None` will autoscale. moving top boundary or to show all contours (Default) """ kwlimits.update(limits) AbstractMatplotlibViewer.__init__(self, vars=[], title=title, **kwlimits) self.distanceVar = distanceVar if surfactantVar is None: self.surfactantVar = numerix.zeros(len(self.distanceVar), 'd') else: self.surfactantVar = surfactantVar self.smooth = smooth self.zoomFactor = zoomFactor self.animate = animate if animate: self._initialCondition = None if distanceVar.mesh.dim != 2: raise MeshDimensionError('The MatplotlibSurfactantViewer only works for 2D meshes.')