[AstroPy] Problem creating all-sky projection with matplotlib

Matt Davis mrdavis@stsci....
Tue Sep 13 13:18:50 CDT 2011


Hi Eduardo,

You are seeing this behavior because imshow works just by filling in rows of the image with rows of your array. In your case, your array is zeros in the bottom quarter and non-zero in the top three-quarters, so that's what you see in the resulting plot. Imshow *does not* account for the projection.

I think you would prefer to use pcolor so that your data is mapped to the projection. See: http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.pcolor

Best,

Matt Davis

On Sep 13, 2011, at 9:38 AM, Eduardo Bañados Torres wrote:

> Hi all,
> 
> I posted this question in Stackoverflow (http://stackoverflow.com/questions/7355497/curious-bad-behavior-creating-all-sky-projections-with-matplotlib) but I haven't get any answer so far, so I hope some of you can help me :-)
> 
> In short, I am plotting a density all-sky plot using the molloweide projection.  I create objects with coordinates ranging from 0 to 360 deg in RA and from -45 to 90 deg in DEC, but the output I get is the following:
> 
> image1.png -> http://i56.tinypic.com/24mu96s.png
> 
> A plot which is OK in RA (0-360) but in DEC ranges only between -35 to 90, so I am missing 10 degrees in the south. 
> 
> But I would expect this image:
> 
> image2.png -> http://oi53.tinypic.com/2yl1nch.jpg
> A plot ranging between 0 to360 and -45 to 90 as it was defined
> 
> I attach the self-contained code to produce these images, I hope someone can tell me if I am doing something wrong that I can't notice now  or misunderstanding something in the code or if there is a curious bug in matplotlib??
> 
> 
> ############the self-contained example################
> import numpy as np
> 
> import matplotlib.pyplot as plt
> import matplotlib.backends.backend_agg
> 
> from math import pi
> 
> #array between 0 and 360 deg
> RA = np.random.random(10000)*360
> 
> #array between -45 and 90 degrees. By construction!
> DEC= np.random.random(10000)*135-45
> 
> 
> fig = plt.Figure((10, 5))
> 
> ax = fig.add_subplot(111,projection='mollweide')
> 
> ax.grid(True)
> ax.set_xlabel('RA')
> 
> ax.set_ylabel('DEC')
> 
> ax.set_xticklabels(np.arange(30,331,30))
> 
> hist,xedges,yedges = np.histogram2d(DEC,RA,bins=[90,180],range=[[-90,90],[0,360]])
> 
> #TO RECOVER THE EXPECTED BEHAVIOUR (image2.png), I HAVE TO CHANGE -90 FOR -80 IN THE PREVIOUS LINE:
> #hist,xedges,yedges = np.histogram2d(DEC,RA,bins=[90,180],range=[[-80,90],[0,360]])
> 
> #I DO NOT WHY!
> 
> extent = (-pi,pi,-pi/2.,pi/2.)
> 
> image = ax.imshow(hist,extent=extent,clip_on=False,aspect=0.5,origin='lower')
> 
> 
> cb = fig.colorbar(image, orientation='horizontal')
> 
> canvas = matplotlib.backends.backend_agg.FigureCanvasAgg(fig)
> 
> 
> fig.canvas.print_figure("image1.png")
> 
> ######################################################
> 
> Thanks,
> 
> 
> 
> -- 
> Eduardo Bañados
> 
> _______________________________________________
> AstroPy mailing list
> AstroPy@scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/astropy/attachments/20110913/7f0212ac/attachment.html 


More information about the AstroPy mailing list