Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6570307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:44:26+00:00 2026-05-25T14:44:26+00:00

I am trying to make a density all-sky plot which is complete in RA

  • 0

I am trying to make a density “all-sky” plot which is complete in RA (i.e 0 to 360 deg) but incomplete in DEC (let’s say from -45 to 90 deg). If I plot this without any projection it is ok, but when I try to plot using the ‘mollweide’ projection I am not recovering the input, but if I do a little change in the code I do recover the expected behavior (however, I don’t have a coherent explanation for this change as you’ll see in the example).

Let’s see a self-contained example with its outputs to be clearer:

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, 4.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, 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")

And the output image is:
[As I am new here I am not allowed to post images, so I will post a link, if it does not work, please write me an email and I can share a Dropbox folder with the images ;)]

Output Image that I am getting

Where you can see clearly that the RA is OK so it ranges between 0 and 360, BUT the DEC ranges from -35 to 90 instead of -45 to 90. So far I do not understand why I am missing 10 deg.

However, if I do a little change in the code, replacing the line

hist,xedges,yedges = np.histogram2d(DEC,RA,bins=[90,180],range=[[-90,90],[0,360]]

for

hist,xedges,yedges = np.histogram2d(DEC,RA,bins=[90,180],range=[[-80,90],[0,360]]

I get what I think I should get, which is this plot:

Output Image 2

[Again, if the link does not work, let me know and I can share a Dropbox folder with you]

where DEC now ranges from -45 to 90 as expected because I created DEC in that way.

However the change of -90 for -80 doesn’t make sense (I think).
So probably I am doing something wrong that I can’t notice now, or I am misunderstanding something in the code or there is a curious bug in matplotlib??

Please any help/hint/correction would be greatly appreciate it

Eduardo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:44:26+00:00Added an answer on May 25, 2026 at 2:44 pm

    If this is useful for someone else, this is the “corrected version” of my code, which gives as output this image. The main change is to use pcolormesh instead of imshow (as @Joe suggested):

    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.backends.backend_agg
    
    #array between 0 and 360 deg
    #CAVEAT: it seems that is needed an array from -180 to 180, so is just a
    #shift in the coordinates
    RA = np.random.random(10000)*360-180
    #array between -45 and 90 degrees
    DEC= np.random.random(10000)*135-45
    
    fig = plt.Figure((10, 5))
    ax = fig.add_subplot(111,projection='mollweide')
    
    ax.set_xlabel('RA')
    ax.set_ylabel('DEC')
    ax.set_xticklabels(np.arange(30,331,30))
    
    hist,xedges,yedges = np.histogram2d(DEC,RA,bins=[60,40],range=[[-90,90],[-180,180]])
    
    X,Y = np.meshgrid(np.radians(yedges),np.radians(xedges))
    
    image = ax.pcolormesh(X,Y,hist)
    ax.grid(True)
    cb = fig.colorbar(image, orientation='horizontal')
    canvas = matplotlib.backends.backend_agg.FigureCanvasAgg(fig)
    fig.canvas.print_figure("image4.png")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a 2D density plot (from some simulation data) with
trying to make a page which will recursively call a function until a limit
im trying make one replace in string from a array but this dont work
I'm trying make a static text which if too long for the sizer, will
I'm trying make one treeView with infinite subgroups. I can add my groups but
I'm trying to make a change to an old appengine application, but now after
I am trying to make a topographic map using different density points for density
trying to make 5 curl childs for curl handler and defining them, but can't
I am trying to make a histogram of density values and overlay that with
I'm trying make some stuff in jQuery using ASP.NET. But the ID from runat=server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.