问题描述
我正在使用 matplotlib 和以下代码(改编自 this answer to another question)在 Python 3.7 中绘制极坐标 2d 直方图:
import numpy as np
import matplotlib.pyplot as plt
# input data
azimut = np.random.rand(3000)*2*np.pi
radius = np.random.rayleigh(9,size=3000)
# binning
rbins = np.linspace(0,radius.max(),10)
abins = np.linspace(0,2*np.pi,10)
# histogram
hist,_,_ = np.histogram2d(azimut,radius,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='inferno')
fig.colorbar(pc)
plt.show()
生成以下图:
由于 bin 尺寸较大,极坐标投影看起来更像多边形而不是圆形。
有什么办法可以绘制这个图,使垃圾箱看起来是弯曲的而不是直的? IE。这样无论 bin 大小如何,绘图始终是圆形的,并且当 bin 较大时不会变成多边形?
最好使用 matplotlib 解决方案,但也欢迎其他解决方案。
非常感谢您的帮助。