[Matplotlib-users] quadrilateral meshes From: John Hunter - 2006-01-20 00:08 ```Alex Mont and Paul Kienzle just contributed a patch for more efficient handling of quadrilateral meshes, which supports non-rectangular meshes. http://peds-pc311.bsd.uchicago.edu/misc/quadmesh.png Right now this is *Agg only, but I think/hope they will be adding support for other backends in the near future. Their original patch with detailed description can be found here https://sourceforge.net/tracker/index.php?func=detail&aid=1409190&group_id=80706&atid=560722 and I just committed this to CVS. Combined with Nicholas Young's nonuniform image, this provides some new alternatives to those needing efficient pseudo-color plots (see http://www.nabble.com/interpolated-pcolor-image-t659211.html for a NonuniformImage example) Thus we now have pcolor - rectangular, possibly nonuniform mesh with optional facets. Slow for large grids. No interpolation. pcolormesh - Arbitrary quadrilateral meshes, agg only, faster than pcolor and more efficient in memory. No interpolation. imshow - Pseudocolor plots with interpolation but no faceting. Faster than pcolor or pcolormesh NonUniformImage - uses image machinery but supports nonuniform, rectangular meshes with interpolation and no faceting. Again, faster than pcolor or pcolormesh. Given the bewildering array of options, it would be nice to have a wiki entry with examples showing when and how to use these various classes and functions. Volunteers welcome; a good starting point would be this email and the example from the nonuniform image link above and the discussion by Alex and Paul on the link at the sourceforge site. Here is a quadrilateral mesh example, which is now examples/quadmesh_demo.py in CVS. from matplotlib.mlab import linspace, meshgrid import matplotlib.numerix as nx from pylab import figure,show n = 56 x = linspace(-1.5,1.5,n) X,Y = meshgrid(x,x); Qx = nx.cos(Y) - nx.cos(X) Qz = nx.sin(Y) + nx.sin(X) Qx = (Qx + 1.1) Z = nx.sqrt(X**2 + Y**2)/5; Z = (Z - nx.mlab.amin(Z)) / (nx.mlab.amax(Z) - nx.mlab.amin(Z)) fig = figure() ax = fig.add_subplot(111) ax.pcolormesh(Qx,Qz,Z) show() ```
 [Matplotlib-users] Re: quadrilateral meshes From: Paul Kienzle - 2006-01-20 02:02 ```John, Alex added facets to pcolormesh today. Eventually we would like pcolormesh to be a drop-in replacement for pcolor, only faster. We are also working on performance improvements. The pcolormesh function can easily identify rectilinear grids (e.g., when given x,y as vector rather than array) and use either NonUniformImage or imshow as appropriate. The facets should be easy enough to draw on top if needed, though obviously the result will be slower. In the end we will have two functions: pcolor and imshow, with pcolor accepting x,y,z and imshow only z. - Paul On Jan 19, 2006, at 6:58 PM, John Hunter wrote: > > Alex Mont and Paul Kienzle just contributed a patch for more efficient > handling of quadrilateral meshes, which supports non-rectangular > meshes. > > http://peds-pc311.bsd.uchicago.edu/misc/quadmesh.png > > Right now this is *Agg only, but I think/hope they will be adding > support for other backends in the near future. > > Their original patch with detailed description can be found here > > > https://sourceforge.net/tracker/index.php? > func=detail&aid=1409190&group_id=80706&atid=560722 > > and I just committed this to CVS. > > Combined with Nicholas Young's nonuniform image, this provides some > new alternatives to those needing efficient pseudo-color plots (see > http://www.nabble.com/interpolated-pcolor-image-t659211.html for a > NonuniformImage example) > > Thus we now have > > pcolor - rectangular, possibly nonuniform mesh with optional facets. > Slow for large grids. No interpolation. > > pcolormesh - Arbitrary quadrilateral meshes, agg only, faster than > pcolor and more efficient in memory. No interpolation. > > imshow - Pseudocolor plots with interpolation but no faceting. Faster > than pcolor or pcolormesh > > NonUniformImage - uses image machinery but supports nonuniform, > rectangular meshes with interpolation and no faceting. Again, > faster than pcolor or pcolormesh. > > Given the bewildering array of options, it would be nice to have a > wiki entry with examples showing when and how to use these various > classes and functions. Volunteers welcome; a good starting point > would be this email and the example from the nonuniform image link > above and the discussion by Alex and Paul on the link at the > sourceforge site. > > Here is a quadrilateral mesh example, which is now > examples/quadmesh_demo.py in CVS. > > from matplotlib.mlab import linspace, meshgrid > import matplotlib.numerix as nx > from pylab import figure,show > > n = 56 > x = linspace(-1.5,1.5,n) > X,Y = meshgrid(x,x); > Qx = nx.cos(Y) - nx.cos(X) > Qz = nx.sin(Y) + nx.sin(X) > Qx = (Qx + 1.1) > Z = nx.sqrt(X**2 + Y**2)/5; > Z = (Z - nx.mlab.amin(Z)) / (nx.mlab.amax(Z) - nx.mlab.amin(Z)) > > fig = figure() > ax = fig.add_subplot(111) > ax.pcolormesh(Qx,Qz,Z) > show() > > ```
 [Matplotlib-users] Re: quadrilateral meshes From: John Hunter - 2006-01-20 02:43 ```>>>>> "Paul" == Paul Kienzle writes: Paul> John, Alex added facets to pcolormesh today. Eventually we Paul> would like pcolormesh to be a drop-in replacement for Paul> pcolor, only faster. We are also working on performance Paul> improvements. Paul> The pcolormesh function can easily identify rectilinear Paul> grids (e.g., when given x,y as vector rather than array) and Paul> use either NonUniformImage or imshow as appropriate. The Paul> facets should be easy enough to draw on top if needed, Paul> though obviously the result will be slower. One might be able to add the faceting as an image overlay, or blend the faceting into the existing image, which would solve the performance problem. The more we can do with images the better, since we get interpolation and superior performance. Ideally, we would have a single rectilinear image object that supports interpolation, nonuniform (but rectilinear) griding, and optional faceting. This would cover every case except non-rectangular quadrilateral meshes, which is where your and Alex's recent contribution would kick in. The image machinery is almost there already: all that is lacking is a faceting option and a consistent interface. Paul> In the end we will have two functions: pcolor and imshow, Paul> with pcolor accepting x,y,z and imshow only z. This looks like the right approach -- in the end it will be nice to reduce the clutter of too many alternatives. The only problem with switching the underlying object (Image vs NonuniformImage vs QuadMesh vs PolygonCollection) is that it would be difficult to deal with the return object in a consistent way. If we had the object described above, we might imagine living with just two functions: imshow on steroids that handles all rectilinear cases, and quadmesh for the others. pcolor would then simply be a thin interface to imshow for matlab with different kwargs for matlab compatibility. Thanks for your help; looking forward to the updates... JDH ```
 [Matplotlib-users] Re: quadrilateral meshes From: Paul Kienzle - 2006-01-20 13:03 ```On Jan 19, 2006, at 9:33 PM, John Hunter wrote: >>>>>> "Paul" == Paul Kienzle writes: > > Paul> John, Alex added facets to pcolormesh today. Eventually we > Paul> would like pcolormesh to be a drop-in replacement for > Paul> pcolor, only faster. We are also working on performance > Paul> improvements. > > Paul> The pcolormesh function can easily identify rectilinear > Paul> grids (e.g., when given x,y as vector rather than array) and > Paul> use either NonUniformImage or imshow as appropriate. The > Paul> facets should be easy enough to draw on top if needed, > Paul> though obviously the result will be slower. > > One might be able to add the faceting as an image overlay, or blend > the faceting into the existing image, which would solve the > performance problem. The more we can do with images the better, since > we get interpolation and superior performance. Ideally, we would have > a single rectilinear image object that supports interpolation, > nonuniform (but rectilinear) griding, and optional faceting. This > would cover every case except non-rectangular quadrilateral meshes, > which is where your and Alex's recent contribution would kick in. Another common case is a skewed mesh, which could be implemented as a simple image transformation. - Paul ```