简体   繁体   English

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

[英]X-axis labels not showing on bar plot

I'm having an issue with my plot only displaying every other label on the x-axis.我的绘图有问题,只在 x 轴上显示所有其他标签。

Code:代码:

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()

This results in :这导致:

在此处输入图片说明

My quickest fix is to use我最快的解决方法是使用

plt.xticks(ind, labels)

But thanks to Trenton's comments, I have come up with an updated solution:但多亏了特伦顿的评论,我想出了一个更新的解决方案:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM