1 回答

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊
ax.set_xticklabels(month)應(yīng)替換為 ax.set_xticklabels(ME_Requests.keys()).
要將標(biāo)簽放在條形之間,您可以減去width/2左側(cè)X條形的標(biāo)簽,并添加width/2右側(cè)X條形的標(biāo)簽。ax.tick_params(axis='x', length=0)可以使用去除刻度線。
import numpy as np
import matplotlib.pyplot as plt
# sample data
ME_Requests = {'John Doe': 47, 'Amanda Doe': 27, 'Maria Doe': 26}
non_ME_Requests = {'John Doe': 105, 'Amanda Doe': 64, 'Maria Doe': 48}
month = "Apr-2020"
X = np.arange(len(ME_Requests))
fig, ax = plt.subplots()
rects1 = ax.bar(X + 0.1, ME_Requests.values(), width=0.2, align='center')
rects2 = ax.bar(X - 0.1, non_ME_Requests.values(), width=0.2, align='center')
ax.legend(('ME_Requests', 'non_ME_Requests'))
ax.set_xticks(X)
ax.set_xticklabels(ME_Requests.keys())
ax.set_title(f"Emails Closed per team member in {month}", fontsize=17)
ax.tick_params(axis='x', length=0)
def autolabel(rects):
"""Attach a text label above each bar in *rects*, displaying its height."""
for rect in rects:
height = rect.get_height()
ax.annotate(f'{height:.0f}',
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 3), # 3 points vertical offset
textcoords="offset points",
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
fig.tight_layout()
plt.show()
添加回答
舉報(bào)