0
我需要註解水平條形圖。 我能夠使用matplotlib網站中顯示的示例註釋垂直條形圖,但對於horizonatl類似的想法似乎不起作用。matplotlib中水平條形圖的註釋
以下是小的垂直
from pylab import *
ops = 90*rand(4) # the bar lengths
pos = arange(4)+.5 # the bar centers on the y axis
rects1 = bar(pos, ops)
def autolabel(rects):
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width()/2., 1.05*height,
'%d' % int(height),
ha='center', va='bottom')
autolabel(rects1)
show()
工作示例以下是我想獲得工作的代碼,但對於水平圖表
from pylab import *
ops = 90*rand(4) # the bar lengths
pos = arange(4)+.5
rects1 = barh(pos, ops)
def autolabel(rects):
for rect in rects:
width = rect.get_width()
plt.text(rect.get_y() - 1.05*rect.get_height()/2., 1.00*width,
'%d' % int(width),
ha='center', va='bottom')
autolabel(rects1)
show()
任何幫助表示讚賞不工作,感謝提前!