Changeset 2475

Show
Ignore:
Timestamp:
02/13/2008 04:35:13 PM (11 months ago)
Author:
wd15
Message:

Fixed Matplotlib2DViewer to be much faster during init by using PolyCollection? rather than fill. There is still a problem with the polygon line widths, resulting in a faint outline of polygon edges

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/fipy/viewers/matplotlibViewer/matplotlib2DViewer.py

    r2341 r2475  
    8989        """ 
    9090        MatplotlibViewer.__init__(self, vars=vars, limits=limits, title=title, figaspect=1. / 1.3) 
    91          
     91 
    9292        self.colorbar = None 
    9393         
     
    102102         
    103103        polys = [] 
     104##         for x, y in zip(xCoords.swapaxes(0,1), yCoords.swapaxes(0,1)): 
     105##             if hasattr(x, 'mask'): 
     106##                 x = x.compressed() 
     107##             if hasattr(y, 'mask'): 
     108##                 y = y.compressed() 
     109##             polys.append(x) 
     110##             polys.append(y) 
     111##             polys.append('b') 
     112 
    104113        for x, y in zip(xCoords.swapaxes(0,1), yCoords.swapaxes(0,1)): 
    105114            if hasattr(x, 'mask'): 
     
    107116            if hasattr(y, 'mask'): 
    108117                y = y.compressed() 
    109             polys.append(x) 
    110             polys.append(y) 
    111             polys.append('b') 
     118            polys.append(zip(x,y)) 
    112119 
    113120        import pylab 
     
    115122 
    116123        fig = pylab.figure(self.id) 
     124 
    117125        ax = fig.get_axes()[0] 
    118         self.polygons = ax.fill(linewidth=0., *polys) 
     126 
     127        from matplotlib.collections import PolyCollection 
     128        self.collection = PolyCollection(polys) 
     129        self.collection.set_linewidth(0) 
     130        ax.add_patch(self.collection) 
     131 
     132        if self._getLimit('xmin') is None: 
     133            xmin = min(numerix.array(self.collection._verts)[:,:,0].flat) 
     134        else: 
     135            xmin = self._getLimit('xmin') 
     136 
     137        if self._getLimit('xmax') is None: 
     138            xmax = max(numerix.array(self.collection._verts)[:,:,0].flat) 
     139        else: 
     140            xmax = self._getLimit('xmax') 
     141 
     142        if self._getLimit('ymin') is None: 
     143            ymin = min(numerix.array(self.collection._verts)[:,:,1].flat) 
     144        else: 
     145            ymin = self._getLimit('ymin') 
     146 
     147        if self._getLimit('ymax') is None: 
     148            ymax = max(numerix.array(self.collection._verts)[:,:,1].flat) 
     149        else: 
     150            ymax = self._getLimit('ymax') 
     151 
     152        pylab.axis((xmin, xmax, ymin, ymax)) 
     153 
     154##        self.polygons = ax.fill(linewidth=0., *polys) 
    119155         
    120156        cbax, kw = matplotlib.colorbar.make_axes(ax, orientation='vertical') 
     
    167203        import pylab 
    168204        import matplotlib 
    169          
    170         for poly, value in zip(self.polygons, Z): 
     205 
     206        faceColors = [] 
     207 
     208        for value in Z: 
    171209            if diff == 0: 
    172210                rgba = pylab.cm.jet(0.5) 
     
    174212                rgba = pylab.cm.jet((value - zmin) / diff) 
    175213 
    176             poly.set_facecolor(rgba) 
     214            faceColors.append(rgba) 
     215 
     216        self.collection.set_facecolors(faceColors) 
     217##        self.collection.set_edgecolors(faceColors) 
     218             
     219##         for poly, value in zip(self.polygons, Z): 
     220##             if diff == 0: 
     221##                 rgba = pylab.cm.jet(0.5) 
     222##             else: 
     223##                 rgba = pylab.cm.jet((value - zmin) / diff) 
     224 
     225##             poly.set_facecolor(rgba) 
    177226             
    178227        self.cb.norm = matplotlib.colors.normalize(vmin=zmin, vmax=zmax) 
    179228        self.cb.draw_all() 
    180229         
    181         pylab.xlim(xmin=self._getLimit('xmin'), 
    182                    xmax=self._getLimit('xmax')) 
    183  
    184         pylab.ylim(ymin=self._getLimit('ymin'), 
    185                    ymax=self._getLimit('ymax')) 
     230##        pylab.xlim(xmin=self._getLimit('xmin'), 
     231##                   xmax=self._getLimit('xmax')) 
     232 
     233##        pylab.ylim(ymin=self._getLimit('ymin'), 
     234##                   ymax=self._getLimit('ymax')) 
    186235 
    187236    def plotMesh(self, filename = None):