2d Polar Histogram with python

2k Views Asked by At

I am trying to do a 2d polar histogram. my data are 2 np.arrays:

azim = [azimuth angles -180 to +180 degrees]
zenith = [zenith angles 0 to 90 degrees]

This is the code i have so far :

# define binning
rbins = np.linspace(0, 90,10)
abins = np.linspace(-180, 180, 30)

#calculate histogram
hist, _, _ = np.histogram2d(azim, zenith, bins=(abins, rbins))
A, R = np.meshgrid(abins, rbins)

# plot
fig, ax = plt.subplots(subplot_kw=dict(projection="polar"))

pc = ax.pcolormesh(A, R, hist.T, cmap="magma_r")
fig.colorbar(pc)
ax.grid(True)
plt.show()

And the plot that i get:

it looks as if part of it is missing and i am not sure why. Also i would like to normalize the zenith angles to solid angle instead of normilizing to one. the formula for the normalization is this, where θ1, θ2 are the bin edges. but i'm not sure how to do the actual normalization:

any suggestions would be really helpful

1

There are 1 best solutions below

3
On

You have to convert your angles in radiant before using polar plots in maptlotlib.