【发布时间】:2020-08-10 23:59:47
【问题描述】:
条形图的代码如下:
xs = sumAgent['Year'].values
ys = sumAgent['agentCom'].values
plt.barh(xs,ys)
我有一个字符串列表: lst = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
我想用以下字符串注释我的条形图(列表的第一个元素 = 第一个条形图的注释)。
for x,y in zip(xs,ys):
label = "{:.2f}".format(y)
plt.annotate('A', # this is the text
(x,y), # this is the point to label
textcoords="offset points", # how to position the text
xytext=(0,10), # distance from text to points (x,y)
ha='center') # horizontal alignment can be left, right or center
当然,它会用值 A 注释所有条形图,并且位置不在条形图内。
关于如何解决这个问题的任何想法?
【问题讨论】:
-
谢谢,但是如何将标签放置在水平条内?
标签: python python-3.x matplotlib