2016-06-13 9 views
0

水平棒グラフに注釈を付ける必要があります。 私はmatplotlibのウェブサイトに示されている例を使って縦棒グラフに注釈を付けることができますが、horizo​​natlの同様の考え方はうまくいかないようです。matplotlibの水平棒グラフの注釈

次は、次は私が働いて取得したいが、水平方向のグラフ

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() 

のために動作しないコードすべてのヘルプ感謝、感謝である垂直

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() 

ための小さな作業例です前進!

答えて

0
def autolabel(rects): 
    for rect in rects: 
     width = rect.get_width() 
     plt.text(1.05*rect.get_width(), rect.get_y()+0.5*rect.get_height(), 
       '%d' % int(width), 
       ha='center', va='center') 

enter image description here

関連する問題