I am a physicist studying about super-galactic objects and I feel like it is difficult to make 2D histogram based on what I want to make.
To avoid confusion and getting answer what I already know. I will show two method which I already know and then I will present customized bin which I want to use.
First is a projection with hexbin.
import numpy as np
import matplotlib.pyplot as plt
lat=2*np.pi*np.random.random(100000)-np.pi
lon=np.pi*np.random.random(100000)-np.pi/2
plt.subplot(111,projection="aitoff")
plt.title("Random Hex binning", fontsize = 20)
plt.hexbin(lat,lon,gridsize=(180,90))
ax=plt.gca()
plt.pause(0.1)
ax.set_xticklabels(ax.get_xticklabels()[::-1]) # Reverse axis
plt.xticks(fontsize=15)
plt.yticks(fontsize=15)
plt.xlabel("Lat",fontsize=18)
plt.ylabel("Lon",fontsize=18)
plt.colorbar()
plt.show()
When I run this I will get something like this.
This could be a basic 2D histogram which we can learn in matplotlib manual but in astrophysics, this is not really useful because each bin does not present same area in terms of spherically curved surface.
What I learned next was something with using Healpy library.
import healpy as hp
from healpy.newvisufunc import projview
import numpy as np
import matplotlib.pyplot as plt
nside=3 #nside is resolution
npix = hp.nside2npix(nside) #npix would be actual bins we will observe. npix = 12 * nside**2
lat=2*np.pi*np.random.random(1000)
lon=np.pi*np.random.random(1000)
indices=hp.ang2pix(nside,lon,lat)
hpmap=np.zeros(npix)
for i in indices:
hpmap[i]=hpmap[i]+1
projview(
hpmap,
coord=["G"],
graticule=True,
graticule_labels=True,
title="Random Binning with healpix",
xlabel="lat",
ylabel="lon",
flip="astro",
projection_type="mollweide",
)
plt.show()
Now I will get someting like this
Healpix have advantage that we can see the equal area of spherically curved 2D surface to 2D flat projection, however, personally, I don't think the shape of projection is straightforward and I don't like that I don't know how analytically this binning is made.
So, this is what I want to use as my binning. I plotted this with my basic calculus knowledge and I can even fill the bins by plt.fill_between function. However, what I want is more I actually want to make 2D histogram based on this customized binning I made. I mean, it seems really difficult to control HVC by just using plt.fill_between. Would there better idea I can choose?