Hello,I want to plot a scalar function on the sphere in a Mollweide projection. My strategy is to:
1. Generate a rectangular mesh in display coordinates,2. Apply the inverse transform for the Mollweide projection to get the data coordinates of every display coordinate,
3. Evaluate the function at each data coordinate, and finally, 4. Plot with imshow.
I noticed that the inverse transform in matplotlib.projections.geo.MollweideAxes is not implemented. I'm attaching a patch that fills in the missing inverse.
Also attached is a minimal example of the type of plot I am interested in making.
Cheers, Leo Singer Graduate Student @ LIGO-Caltech
0001-Defined-the-inverse-transform-for-Mollweide-projecti.patch
Description: Binary data
#!/usr/bin/env python from matplotlib import cm import pylab import numpy # Construct new axes with Mollweide projection ax = pylab.subplot(111, projection='mollweide') ax.grid() # Set up rectangular grid in display coordinates x = numpy.arange(ax.bbox.x0, ax.bbox.x1 + 1, 1) y = numpy.arange(ax.bbox.y0, ax.bbox.y1 + 1, 1) xx, yy = numpy.meshgrid(x, y) # Apply inverse transform to get from display to data coordinates longitudes, latitudes = ax.transData.inverted().transform( numpy.vstack((xx.flatten(), yy.flatten())).T).T # Construct a scalar function of data coordinates map = longitudes * latitudes # Mask out values that are outside Mollweide projection boundaries map = numpy.ma.array(map, mask=((longitudes < -numpy.pi) | (longitudes > numpy.pi))) # Plot image xmin, xmax = ax.get_xlim() ymin, ymax = ax.get_ylim() cmap = cm.jet cmap.set_bad('w', alpha=1.) pylab.imshow(map.reshape(xx.shape), aspect=0.5, extent=(xmin, xmax, ymax, ymin), cmap=cmap) pylab.savefig('moll_example.png')
P.S. Some digging revealed another library (in Java) that implements an inverse Mollweide projection; their method is similar to the one I in my patch, except that my method has slightly fewer trig function evaluations. Here is the source:
http://svn.osgeo.org/geotools/trunk/modules/library/referencing/src/main/java/org/geotools/referencing/operation/projection/Mollweide.java
------------------------------------------------------------------------------ Get a FREE DOWNLOAD! and learn more about uberSVN rich system, user administration capabilities and model configuration. Take the hassle out of deploying and managing Subversion and the tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel