我只想将百分比值添加到matplotlib直方图中的条形图顶部。这就是我目前所拥有的。有什么办法吗?我知道也有类似的帖子,但我只看到了单杠或海生图上的东西。谢谢
x = [2.5, 10.4, 0.5, 1.2, 4.6, 3.6, 0.8, 2.5, 2.9, 1.6, 9.4, 4.9, 2.6, 4.2, 3.9]
myplot = plt.hist(x, bins = [0,1,2,3,10],weights=np.ones(len(x)) / len(x))
plt.gca().yaxis.set_major_formatter(PercentFormatter(1))
total = float(len(x))
plt.show()
恐怕
plt.hist
不可能,但我会尽力提供尽可能接近您需要的东西-使用
plt.text()
将文本放入绘图中例如:
这将是输出:
及供参考How to display the value of the bar on each bar with pyplot.barh()?
相关问题 更多 >
编程相关推荐