Ejemplo n.º 1
0
    def __init__(self, vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, **kwlimits):
        """
        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
        """
        kwlimits.update(limits)
        _MatplotlibViewer.__init__(self, vars=vars, title=title, 
                                   cmap=cmap, colorbar=colorbar, axes=axes, 
                                   **kwlimits)

        self.image = self.axes.imshow(self._getData(),
                                      extent=(self._getLimit('xmin'), self._getLimit('xmax'), 
                                              self._getLimit('ymin'), self._getLimit('ymax')),
                                      vmin=self._getLimit(key=('datamin', 'zmin')),
                                      vmax=self._getLimit(key=('datamax', 'zmax')),
                                      cmap=self.cmap)
                   
        if title is None:                          
            self.axes.set_title(self.vars[0].getName())
Ejemplo n.º 2
0
    def __init__(self, vars, title=None, scale=None, sparsity=None, limits={}, **kwlimits):
        """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.

        """
        kwlimits.update(limits)
        _MatplotlibViewer.__init__(self, vars=vars, title=title, **kwlimits)

        self.quiver(sparsity=sparsity, scale=scale)
        self.colorbar = False
        
        self._plot()
 def __init__(self, vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, **kwlimits):
     """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
     """
     kwlimits.update(limits)
     _MatplotlibViewer.__init__(self, vars=vars, title=title, 
                                cmap=cmap, colorbar=colorbar, axes=axes, 
                                **kwlimits)
     
     self._plot()
Ejemplo n.º 4
0
 def __init__(self, vars, title=None, limits={}, **kwlimits):
     """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.
     """
     kwlimits.update(limits)
     _MatplotlibViewer.__init__(self, vars=vars, title=title, **kwlimits)
     
     self.colorbar = None
     self._plot()
     
     import pylab
     # colorbar will not automatically update
     # http://sourceforge.net/mailarchive/forum.php?thread_id=10159140&forum_id=33405
     ##from fipy.tools.numerix import array
     ##self.colorbar = pylab.colorbar(array(self.vars[0]))
     self.colorbar = pylab.colorbar()
Ejemplo n.º 5
0
    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)
        _MatplotlibViewer.__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._getData()]
        elif xlog:
            self.lines = [self.axes.semilogx(*datum) for datum in self._getData()]
        elif ylog:
            self.lines = [self.axes.semilogy(*datum) for datum in self._getData()]
        else:
            self.lines = [self.axes.plot(*datum) for datum in self._getData()]

        if legend is not None:
            self.axes.legend([var.getName() 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)
Ejemplo n.º 6
0
    def __init__(self, vars, title=None, limits={}, cmap=None, **kwlimits):
        """
        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 `pylab.cm.jet`
          xmin, xmax, ymin, ymax, datamin, datamax
            displayed range of data. Any limit set to 
            a (default) value of `None` will autoscale.

        """
        kwlimits.update(limits)
        _MatplotlibViewer.__init__(self, vars=vars, title=title, **kwlimits)

        import pylab

        if cmap is None:
            self.cmap = pylab.cm.jet
        else:
            self.cmap = cmap

        self.image = pylab.imshow(self._getData(),
                                  extent=(self._getLimit('xmin'), self._getLimit('xmax'), 
                                          self._getLimit('ymin'), self._getLimit('ymax')),
                                  vmin=self._getLimit(key=('datamin', 'zmin')),
                                  vmax=self._getLimit(key=('datamax', 'zmax')),
                                  cmap=self.cmap)
                   
        if title is None:                          
            pylab.title(self.vars[0].getName())

        # colorbar will not automatically update
        # http://sourceforge.net/mailarchive/forum.php?thread_id=10159140&forum_id=33405
        self.colorbar = pylab.colorbar()
        self.colorbar.set_label(self.vars[0].getName())
Ejemplo n.º 7
0
    def __init__(self, vars, title=None, limits={}, cmap=None, colorbar=True, axes=None, **kwlimits):
        """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
        """
        kwlimits.update(limits)
        _MatplotlibViewer.__init__(self, vars=vars, title=title, figaspect=1. / 1.3, 
                                   cmap=cmap, colorbar=colorbar, axes=axes, 
                                   **kwlimits)

        self.mesh = self.vars[0].getMesh()
        
        vertexIDs = self.mesh._getOrderedCellVertexIDs()

        vertexCoords = self.mesh.getVertexCoords()

        xCoords = numerix.take(vertexCoords[0], vertexIDs)
        yCoords = numerix.take(vertexCoords[1], vertexIDs)
        
        polys = []

        for x, y in zip(xCoords.swapaxes(0,1), yCoords.swapaxes(0,1)):
            if hasattr(x, 'mask'):
                x = x.compressed()
            if hasattr(y, 'mask'):
                y = y.compressed()
            polys.append(zip(x,y))

        import matplotlib

        from matplotlib.collections import PolyCollection
        self.collection = PolyCollection(polys)
        self.collection.set_linewidth(0.5)
        try:
            self.axes.add_patch(self.collection)
        except:
            # PolyCollection not child of PatchCollection in matplotlib 0.98
            self.axes.add_collection(self.collection)

        xmin = self._getLimit('xmin', default=xCoords.min())
        xmax = self._getLimit('xmax', default=xCoords.max())
        ymin = self._getLimit('ymin', default=yCoords.min())
        ymax = self._getLimit('ymax', default=yCoords.max())

        self.axes.set_xlim(xmin=xmin, xmax=xmax)
        self.axes.set_ylim(ymin=ymin, ymax=ymax)

        self._plot()
Ejemplo n.º 8
0
    def __init__(self, vars, title=None, limits={}, cmap=None, **kwlimits):
        """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 `pylab.cm.jet`
          xmin, xmax, ymin, ymax, datamin, datamax
            displayed range of data. Any limit set to 
            a (default) value of `None` will autoscale.

        """
        kwlimits.update(limits)
        _MatplotlibViewer.__init__(self, vars=vars, title=title, figaspect=1. / 1.3, **kwlimits)

        self.colorbar = None
        
        self.mesh = self.vars[0].getMesh()
        
        vertexIDs = self.mesh._getOrderedCellVertexIDs()

        vertexCoords = self.mesh.getVertexCoords()

        xCoords = numerix.take(vertexCoords[0], vertexIDs)
        yCoords = numerix.take(vertexCoords[1], vertexIDs)
        
        polys = []

        for x, y in zip(xCoords.swapaxes(0,1), yCoords.swapaxes(0,1)):
            if hasattr(x, 'mask'):
                x = x.compressed()
            if hasattr(y, 'mask'):
                y = y.compressed()
            polys.append(zip(x,y))

        import pylab
        import matplotlib

        fig = pylab.figure(self.id)

        ax = fig.get_axes()[0]

        from matplotlib.collections import PolyCollection
        self.collection = PolyCollection(polys)
        self.collection.set_linewidth(0.5)
        try:
            ax.add_patch(self.collection)
        except:
            # PolyCollection not child of PatchCollection in matplotlib 0.98
            ax.add_collection(self.collection)

        if self._getLimit('xmin') is None:
            xmin = xCoords.min()
        else:
            xmin = self._getLimit('xmin')

        if self._getLimit('xmax') is None:
            xmax = xCoords.max()
        else:
            xmax = self._getLimit('xmax')

        if self._getLimit('ymin') is None:
            ymin = yCoords.min()
        else:
            ymin = self._getLimit('ymin')

        if self._getLimit('ymax') is None:
            ymax = yCoords.max()
        else:
            ymax = self._getLimit('ymax')

        pylab.axis((xmin, xmax, ymin, ymax))

        cbax, kw = matplotlib.colorbar.make_axes(ax, orientation='vertical')
        
        # Set the colormap and norm to correspond to the data for which
        # the colorbar will be used.
        if cmap is None:
            self.cmap = matplotlib.cm.jet
        else:
            self.cmap = cmap
            
        norm = matplotlib.colors.normalize(vmin=-1, vmax=1)
        
        # ColorbarBase derives from ScalarMappable and puts a colorbar
        # in a specified axes, so it has everything needed for a
        # standalone colorbar.  There are many more kwargs, but the
        # following gives a basic continuous colorbar with ticks
        # and labels.
        self.cb = matplotlib.colorbar.ColorbarBase(cbax, cmap=self.cmap,
                                                   norm=norm,
                                                   orientation='vertical')
        self.cb.set_label(self.vars[0].name)
        
        self._plot()