这是典型的 matplotlib:可以完成,但需要一些工作。
def label(rects, texts):
"""Attach a text label on each rect"""
for rect, txt in zip(rects, texts):
height = rect.get_height()
if height != 0:
plt.text(
rect.get_x() + rect.get_width() / 2.0,
height / 2.0,
txt,
ha='center',
va='center',
fontsize=9,
rotation='vertical',
)
b = plt.bar([i for i in range(1, 24)], [i for i in range(1, 24)])
texts = [f'{k}' for k in range(24)]
label(b, texts)
plt.title('Chart by hours in total')
您可以根据需要调整代码。目前,它在每个条的中点插入垂直方向的文本。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句