这只是极坐标投影中的水平条形图。 Matplotlib 默认设置会让它看起来有点不同。
ax = plt.subplot(projection='polar')
ax.barh(0, math.radians(150))
ax.barh(1, math.radians(300))
ax.barh(2, math.radians(270))
ax.barh(3, math.radians(320))
但可以调整:
- 使用
set_theta_zero_location() 使条形图从北开始。
- 使用
set_theta_direction() 使条形顺时针方向移动。
- 使用
set_rlabel_position() 移动径向标签。
- 使用
set_thetagrids() 和set_rgrids() 设置刻度和标签。
结果非常相似:
ax.set_theta_zero_location('N')
ax.set_theta_direction(-1)
ax.set_rlabel_position(0)
ax.set_thetagrids([0, 96, 192, 288], labels=[0, 20, 40, 60])
ax.set_rgrids([0, 1, 2, 3], labels=['a', 'b', 'c', 'd'])
一定有办法将径向标签移动到条形的左侧,但我找不到。
PS更简洁,也许更快的方式:
ax.barh([0, 1, 2, 3], np.radians([150, 300, 270, 320]),
color=plt.rcParams['axes.prop_cycle'].by_key()['color'])