2014-08-27 232 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')