炎炎设计
我想您的主要问题是您将文本y有效地放置在方向上1.1 * i.get_height(),而没有考虑初始偏移量i.get_y()。试试这个:for i in ax_mult.patches: ix,iy=i.get_x(),i.get_y() ## gives you the bottom left of each patch width,height=i.get_width(),i.get_height() ## the width & height of each patch ## to place the annotation at the center (0.5, 0.5): ax.annotate(str(height),(ix+0.5*width, iy+0.5*height),ha="center",va="center") ## alternatively via ax.text(): # ax.text(ix+.5*width,iy+.5*height,height,ha="center",va="center" ) 请注意,您可能需要使用良好的偏移“玩转”,尤其是在 y 方向。该ha="center",va="center"参数正好对准在所选择的坐标文本(同时在水平:HA和垂直:VA),其中就派上用场了,如果你想放的标签如补丁的顶端对齐如下:ax.annotate(str(height),(ix+0.5*width, iy+1.0*height),ha="center",va="top")或者就在补丁的顶端上方:ax.annotate(str(height),(ix+0.5*width, iy+1.0*height),ha="center",va="bottom")