条形图的代码如下所示:
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注释所有条形图,并且位置不在条形图内
有没有办法解决这个问题
这里有一个例子,使用了这里答案的修改版本:https://stackoverflow.com/a/51410758/42346
结果:
相关问题 更多 >
编程相关推荐