【发布时间】:2018-07-23 23:42:43
【问题描述】:
我有一个以度为单位的角度列表。我想显示一个极坐标直方图,其中 [0°, 360°) 值范围被细分为相等的 bin,并显示角度列表中有多少值落入每个 bin。我使用以下代码获取直方图数据(并且我已检查它是否正确):
bins_number = 8 # the [0, 360) interval will be subdivided into this number of equal bins
bins = np.linspace(0.0, 360.0, bins_number + 1)
n, _, _ = plt.hist(angles, bins)
现在,我尝试使用以下代码将此数据绘制成极坐标直方图:
plt.clf()
width = 2 * np.pi / bins_number
ax = plt.subplot(1, 1, 1, projection='polar')
bars = ax.bar(bins[:bins_number], n, width=width, bottom=0.0)
for bar in bars:
bar.set_alpha(0.5)
plt.show()
如您所见,条形的放置角度不正确,其中一些相互重叠,而它们应该都是连续的而不重叠。
我做错了什么?提前谢谢你。
【问题讨论】:
-
尝试使用radians,乘以2pi再除以360°。
标签: python matplotlib histogram polar-coordinates