matplotlib polar 2d histogram

牧云@^-^@ 提交于 2019-12-05 22:06:08

Your code works if you explicitly pass a mgrid (with similar characteristics than your a bins and sbins) to the pcolormesh command.

Below is an example inspired by your code:

import matplotlib.pyplot as plt
import numpy as np

#Generate the data
size = 200

baz = 10*np.random.randint(20, 25, size)*np.pi/180.
freq = 10*np.random.randint(1, 10, size)
pwr = 10*np.random.randint(-10, -1, size)

abins = np.linspace(0, 2*np.pi, 360)      # 0 to 360 in steps of 360/N.
sbins = np.linspace(1, 100, 50) 
H, xedges, yedges = np.histogram2d(baz, freq, bins=(abins,sbins), weights=pwr)

#Grid to plot your data on using pcolormesh
theta, r = np.mgrid[0:2*np.pi:360j, 1:100:50j]

fig, ax = plt.subplots(figsize=(14,14), subplot_kw=dict(projection='northpolar'))
ax.pcolormesh(theta, r, H)

ax.set_yticklabels([]) #remove yticklabels

plt.show()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!