快速阅读文档会有所帮助,可以在这里找到:
这里。我使用了文档中描述的annotate函数。
以下是一段代码,它可以为x轴完成您需要的操作。这段代码的大部分来自您在问题中提供链接的示例。
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)
ind = np.arange(N)
width = 0.35
fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)
womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)
rects2 = ax.bar(ind + width, womenMeans, width, color='y', yerr=womenStd)
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width)
ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5'))
ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))
ax.annotate('', xy=(0, -2),xytext=(3,-2.09),
arrowprops=dict(arrowstyle='<->',facecolor='red'),
annotation_clip=False)
ax.annotate('xyz',xy=(1.1,-3.8),xytext=(1.3,-3.8),
annotation_clip=False)
ax.annotate('', xy=(3.1, -2),xytext=(5,-2.09),
arrowprops=dict(arrowstyle='<->',facecolor='red'),
annotation_clip=False)
ax.annotate('abc',xy=(3.6,-3.8),xytext=(3.9,-3.8),
annotation_clip=False)
def autolabel(rects):
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')
autolabel(rects1)
autolabel(rects2)
plt.show()
这将给出下面的图像:
![enter image description here](https://istack.dev59.com/1VnEN.webp)
您需要复制此内容以便对y轴进行相同操作。