【发布时间】:2018-10-23 18:07:36
【问题描述】:
到目前为止,我一直在尝试移动 yticklabel,但没有成功。无论verticalaligment 和horizontalalignment 是什么,yticklabels 的位置,在这种情况下,0.5、1.0、1.5 将始终相同。
我想把它放在水平线的下方。更改rlabel 将旋转标签,我只想将它们转换到线以下。
import numpy
from windrose import WindroseAxes
import matplotlib.pyplot as plt
rose_angle = [25, 45, 45, 90, 125, 142, 165]
damage = [1, 1, 3, 1, 2, 1.3, 3]
ax = WindroseAxes.from_ax()
viridis = plt.get_cmap('viridis')
ax.bar(rose_angle, damage, normed=False, opening=0.8, edgecolor='white', nsector=36, cmap=viridis, bins=[1., 1.5, 2.01])
ax.set_xticklabels(['90$^0$', '', '0$^0$', '', '', '', '0$^0$', ''])
ax.set_theta_zero_location("N")
ax.set_rlabel_position(270) # get radial labels away from plotted line
ax.set_legend(labels = ['Tensile Dominant', 'Shear Dominant', 'Mixed Mode'], title="Failure Mode", bbox_to_anchor=(0.005 , 0.95), loc='center')
ax.set_yticks(numpy.arange(0.5, 2, step=0.5))
ax.set_yticklabels(numpy.arange(0.5, 2, step=0.5), verticalalignment='bottom', horizontalalignment='right')
plt.suptitle("Time Step")
plt.show()
【问题讨论】:
-
您需要
verticalalignment='top'才能在该行下方添加标签。 -
@ImportanceOfBeingErnest:同样的问题。我会更新答案以显示它。
-
这是 matplotlib 2.2.2 中的一个问题。它已在 github.com/matplotlib/matplotlib/pull/10792 中修复,因此可从 matplotlib 2.2.3 开始使用。
-
@ImportanceOfBeingErnest 如果您将其作为答案发布,我可以接受。感谢您指出错误,我开始失去理智了。
标签: python matplotlib label polar-coordinates