1

I am using matplotlib.pyplot and astropy to build a plot in galactic coordinates and my goal is to show the density of stars in the sky.

For that, the only data I have is a two-column table with the coordinates of the stars in Right Ascension (RA) and Declination (Dec).

Right now my code is doing the following:

import astropy.coordinates as coord
import matplotlib.pyplot as plt
import astropy.units as u

coordinates = coord.SkyCoord(ra=RA*u.deg, dec=DEC*u.deg)

fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection="aitoff")
ax.plot(coordinates.galactic.l.wrap_at('180d').radian, 
        coordinates.galactic.b.radian, 'k.', alpha=0.01, ms=1)
ax.grid(True)

So for now I am basically using plt.plot to plot all datapoints (which in the case is half-million datapoints) using a very low alpha and symbol size and the plot looks like this:

enter image description here

However, this isn't the plot I want, as the colour scale quickly saturates.

My question is: Is there a way of making a similar plot but properly reflecting the density of datapoint in the z-axis (color)? For example, I want to be able of controling the color table for a given number-density of sources.

I've seen some answers to similar questions are available. For example, this question (Plotting a heatmap in galactic coordinates) does a similar thing, but for a specific z-axis described by some data.

I am also aware of this question (How can I make a scatter plot colored by density in matplotlib?) and I tried each solution in this post, but they all failed since I am using a subplot which already has a projection.

Any ideas?

Julia Roquette
  • 537
  • 1
  • 6
  • 17

0 Answers0