[AstroPy] Problem creating all-sky projection with matplotlib

Eduardo Bañados Torres eebanado at uc.cl
Tue Sep 13 09:38:22 EDT 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20110913/725fb04a/attachment.html>


More information about the AstroPy mailing list