2014-08-27 233 views
0

我試圖將千位分隔符添加到條形圖子圖中。將千位分隔符添加到matplotlib子標籤條標籤

我有一個逗號功能

def comma(x, pos): 
    return format(x, "6,.0f") 

和自動標籤功能

def autolabel(rects): 
    for rect in rects: 
     height = rect.get_height() 
     ax.text(rect.get_x()+rect.get_width()/2., 1.0*height, '%d'%int(height), 
        ha='center', va='bottom') 

rects = ax.bar(ind+width, bar_values, width, color='orange', align='center') 

我可以調用使用逗號函數y軸使用

ax.yaxis.set_major_formatter(tkr.FuncFormatter(comma)) 

我怎麼能使用逗號函數在繪製rects時?

+0

感謝@tcaswell指着我在正確的方向。我結束了使用'{:,。0f}'格式(高度),並做了訣竅。 – user2954587 2014-09-02 16:40:45

回答

0

只要改變你如何格式化字符串:

def autolabel(rects): 
    for rect in rects: 
     height = rect.get_height() 
     ax.text(rect.get_x()+rect.get_width()/2., 1.0*height, comma(height), 
        ha='center', va='bottom')