【发布时间】:2021-05-05 22:22:07
【问题描述】:
我正在使用 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 解决方案更可取,但也欢迎其他解决方案。
非常感谢您的帮助。
【问题讨论】:
标签: python python-3.x numpy matplotlib histogram2d