1
在显示图表上的实际值时有疑问。我有一个印刷图表,需要显示每个堆积条的值。我如何显示这些值?使用matplotlib在每个堆积条上的Y值
我试过ax.text
函数,但它没有给出想要的结果(见图)。因为图表被标准化为1,所以我需要显示每个堆积条的实际值(顶部是总数,它应该分成每个条 - 第一个条应该有1个数字7,第二个条应该有3个数字,其中数字41被每个彩条的大小分割)。是否有可能做到这一点?
我的代码,我怎么拿出多个堆叠条:
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
ha='center', va='bottom')
p = [] # list of bar properties
def create_subplot(matrix, colors, axis):
bar_renderers = []
ind = np.arange(matrix.shape[1])
bottoms = np.cumsum(np.vstack((np.zeros(matrix.shape[1]), matrix)), axis=0)[:-1]
for i, row in enumerate(matrix):
print bottoms[i]
r = axis.bar(ind, row, width=0.5, color=colors[i], bottom=bottoms[i])
bar_renderers.append(r)
autolabel(r)
#axis.set_title(title,fontsize=28)
return bar_renderers
p.extend(create_subplot(nauja_matrica,spalvos, ax))
谢谢你非常感谢你!你是一个救星;) – orangutangas