X 轴标签未显示在条形图上

X-axis labels not showing on bar plot

我的绘图有问题,它只在 x 轴上显示所有其他标签。

代码:

m_count=  [12, 12, 13, 16, 12, 12, 13, 16, 9, 10]
f_count =[13, 13, 12, 9, 13, 13, 11, 9, 15, 15]
    
labels = ["Capomulin", "Ceftamin", "Infubinol", "Ketapril", "Naftisol", "Placebo", "Propriva", "Ramicane", "Stelasyn", "Zoniferol"]
N=10
ind = np.arange(N)
width = .35
fig= plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.bar(ind, m_count, width, color ="b")
ax.bar(ind, f_count, width, color ="r", bottom=m_count)
ax.set_ylabel('Count')
ax.set_title("Count of Mice by Drug Regimen")
ax.set_xticks(ind, labels)
ax.set_xticklabels(labels, rotation=90 )
ax.set_yticks(np.arange(0, 30, 2))
ax.legend(labels=['Male', 'Female'])
plt.show()

这导致:

我最快的解决方法是使用

plt.xticks(ind, labels)

但感谢 Trenton 的评论,我想出了一个更新的解决方案:

ax.set_xticks(ind)
ax.set_xticklabels(labels)