开发者社区> 问答> 正文

如何在matplotlib中获得多行x轴标签?

我试图得到很长的x轴标签多线,如在包围的右图像:

我目前使用的代码:

ax = cluster3.plot(x='Neighborhood',y=['Population'],kind='bar',alpha=0.75,title='Population of Each Neighborhood',figsize=(15, 10))
ax.set_ylabel('Population')

cluster3是具有邻居列的dataframe 问题来源StackOverflow 地址:/questions/59466109/how-to-get-x-axis-labels-in-multiple-line-in-matplotlib

展开
收起
kun坤 2019-12-25 15:52:55 12311 0
1 条回答
写回答
取消 提交回答
  • .x——表示x刻度的取值范围 2.xlabels——表示与x每个值相对应的标签

    例如(x取值范围与xs不相同时): import matplotlib.pyplot as plt xs=range(36) y=xs plt.plot(xs,y) x=range(6) labels=['i','is','the','labels','for','x'] plt.xticks(x,labels) plt.show()

    因为xs取值范围为0到35,而x取值范围为0到5,所以标签只会在x轴的前六个上显示,那么将x范围变为xs会什么样呢 image.png 再如,x与xs取值范围相同时,但labels的值仍然不变时会出现以下效果

    import matplotlib.pyplot as plt xs=range(36) y=xs plt.plot(xs,y) x=xs labels=['i','is','the','labels','for','x'] plt.xticks(x,labels) plt.show()

    2021-02-26 14:40:11
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载