对在图表上显示实际值有疑问。我确实有一个打印的图表,需要显示每个堆叠条的值。如何显示这些值?
我已经尝试过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))