<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi Eduardo,</div><div><br></div><div>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.</div><div><br></div><div>I think you would prefer to use pcolor so that your data is mapped to the projection. See:&nbsp;<a href="http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.pcolor">http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.pcolor</a></div><div><br></div><div>Best,</div><div><br></div><div>Matt Davis</div><br><div><div>On Sep 13, 2011, at 9:38 AM, Eduardo Baņados Torres wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><div dir="ltr"><span class="gI"></span>Hi all,<br><br>I posted this question in Stackoverflow (<a href="http://stackoverflow.com/questions/7355497/curious-bad-behavior-creating-all-sky-projections-with-matplotlib">http://stackoverflow.com/questions/7355497/curious-bad-behavior-creating-all-sky-projections-with-matplotlib</a>) but I haven't get any answer so far, so I hope some of you can help me :-)<br>
<br>In short, I am plotting a density all-sky plot using the molloweide projection.&nbsp; 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:<br>
<br>image1.png -&gt; <a href="http://i56.tinypic.com/24mu96s.png">http://i56.tinypic.com/24mu96s.png</a><br><br>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. <br>
<br>But I would expect this image:<br><br>image2.png -&gt; <a href="http://oi53.tinypic.com/2yl1nch.jpg">http://oi53.tinypic.com/2yl1nch.jpg</a><br>A plot ranging between 0 to360 and -45 to 90 as it was defined<br><br>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&nbsp; or misunderstanding something in the code or if there is a curious bug in 
matplotlib??<br><br><br>############the self-contained example################<br><pre class="default prettyprint"><code><span class="kwd">import</span><span class="pln"> numpy </span><span class="kwd">as</span><span class="pln"> np<br>
</span><span class="kwd">import</span><span class="pln"> matplotlib</span><span class="pun">.</span><span class="pln">pyplot </span><span class="kwd">as</span><span class="pln"> plt<br></span><span class="kwd">import</span><span class="pln"> matplotlib</span><span class="pun">.</span><span class="pln">backends</span><span class="pun">.</span><span class="pln">backend_agg<br>
</span><span class="kwd">from</span><span class="pln"> math </span><span class="kwd">import</span><span class="pln"> pi<br><br></span><span class="com">#array between 0 and 360 deg</span><span class="pln"><br>RA </span><span class="pun">=</span><span class="pln"> np</span><span class="pun">.</span><span class="pln">random</span><span class="pun">.</span><span class="pln">random</span><span class="pun">(</span><span class="lit">10000</span><span class="pun">)*</span><span class="lit">360</span><span class="pln"><br>
</span><span class="com">#array between -45 and 90 degrees. By construction!</span><span class="pln"><br>DEC</span><span class="pun">=</span><span class="pln"> np</span><span class="pun">.</span><span class="pln">random</span><span class="pun">.</span><span class="pln">random</span><span class="pun">(</span><span class="lit">10000</span><span class="pun">)*</span><span class="lit">135</span><span class="pun">-</span><span class="lit">45</span><span class="pln"><br>
<br>fig </span><span class="pun">=</span><span class="pln"> plt</span><span class="pun">.</span><span class="typ">Figure</span><span class="pun">((</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> 5</span><span class="lit"></span><span class="pun">))</span><span class="pln"><br>
ax </span><span class="pun">=</span><span class="pln"> fig</span><span class="pun">.</span><span class="pln">add_subplot</span><span class="pun">(</span><span class="lit">111</span><span class="pun">,</span><span class="pln">projection</span><span class="pun">=</span><span class="str">'mollweide'</span><span class="pun">)</span><span class="pln"><br>
ax</span><span class="pun">.</span><span class="pln">grid</span><span class="pun">(</span><span class="kwd">True</span><span class="pun">)</span><span class="pln"><br>ax</span><span class="pun">.</span><span class="pln">set_xlabel</span><span class="pun">(</span><span class="str">'RA'</span><span class="pun">)</span><span class="pln"><br>
ax</span><span class="pun">.</span><span class="pln">set_ylabel</span><span class="pun">(</span><span class="str">'DEC'</span><span class="pun">)</span><span class="pln"><br><br>ax</span><span class="pun">.</span><span class="pln">set_xticklabels</span><span class="pun">(</span><span class="pln">np</span><span class="pun">.</span><span class="pln">arange</span><span class="pun">(</span><span class="lit">30</span><span class="pun">,</span><span class="lit">331</span><span class="pun">,</span><span class="lit">30</span><span class="pun">))</span><span class="pln"><br>
hist</span><span class="pun">,</span><span class="pln">xedges</span><span class="pun">,</span><span class="pln">yedges </span><span class="pun">=</span><span class="pln"> np</span><span class="pun">.</span><span class="pln">histogram2d</span><span class="pun">(</span><span class="pln">DEC</span><span class="pun">,</span><span class="pln">RA</span><span class="pun">,</span><span class="pln">bins</span><span class="pun">=[</span><span class="lit">90</span><span class="pun">,</span><span class="lit">180</span><span class="pun">],</span><span class="pln">range</span><span class="pun">=[[-</span><span class="lit">90</span><span class="pun">,</span><span class="lit">90</span><span class="pun">],[</span><span class="lit">0</span><span class="pun">,</span><span class="lit">360</span><span class="pun">]])</span><span class="pln"><br>
</span><span class="com">#TO RECOVER THE EXPECTED BEHAVIOUR (image2.png), I HAVE TO CHANGE -90 FOR -80 IN THE PREVIOUS LINE:</span><span class="pln"><br></span><span class="com">#hist,xedges,yedges = np.histogram2d(DEC,RA,bins=[90,180],range=[[-80,90],[0,360]])</span><span class="pln"><br>
</span><span class="com">#I DO NOT WHY!</span><span class="pln"><br><br>extent </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(-</span><span class="pln">pi</span><span class="pun">,</span><span class="pln">pi</span><span class="pun">,-</span><span class="pln">pi</span><span class="pun">/</span><span class="lit">2.</span><span class="pun">,</span><span class="pln">pi</span><span class="pun">/</span><span class="lit">2.</span><span class="pun">)</span><span class="pln"><br>
image </span><span class="pun">=</span><span class="pln"> ax</span><span class="pun">.</span><span class="pln">imshow</span><span class="pun">(</span><span class="pln">hist</span><span class="pun">,</span><span class="pln">extent</span><span class="pun">=</span><span class="pln">extent</span><span class="pun">,</span><span class="pln">clip_on</span><span class="pun">=</span><span class="kwd">False</span><span class="pun">,</span><span class="pln">aspect</span><span class="pun">=</span><span class="lit">0.5</span><span class="pun">,</span><span class="pln">origin</span><span class="pun">=</span><span class="str">'lower'</span><span class="pun">)</span><span class="pln"><br>
<br>cb </span><span class="pun">=</span><span class="pln"> fig</span><span class="pun">.</span><span class="pln">colorbar</span><span class="pun">(</span><span class="pln">image</span><span class="pun">,</span><span class="pln"> orientation</span><span class="pun">=</span><span class="str">'horizontal'</span><span class="pun">)</span><span class="pln"><br>
canvas </span><span class="pun">=</span><span class="pln"> matplotlib</span><span class="pun">.</span><span class="pln">backends</span><span class="pun">.</span><span class="pln">backend_agg</span><span class="pun">.</span><span class="typ">FigureCanvasAgg</span><span class="pun">(</span><span class="pln">fig</span><span class="pun">)</span><span class="pln"><br>
<br>fig</span><span class="pun">.</span><span class="pln">canvas</span><span class="pun">.</span><span class="pln">print_figure</span><span class="pun">(</span><span class="str">"image1.png"</span><span class="pun">)</span><span class="pln"><br>
</span></code></pre>######################################################<br><br>Thanks,<br><br><br><br>-- <br>Eduardo Baņados<br><br>
</div>
_______________________________________________<br>AstroPy mailing list<br><a href="mailto:AstroPy@scipy.org">AstroPy@scipy.org</a><br>http://mail.scipy.org/mailman/listinfo/astropy<br></blockquote></div><br></body></html>