Matplotlib:使范围内的所有值显示在x轴上 [英] Matplotlib: Make all values in range show up on x axis

查看:147
本文介绍了Matplotlib:使范围内的所有值显示在x轴上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人请指导我如何确保在使用matplotlib绘图时应该确保所有刻度(或者更好的指定方式是将列表中所有传递给绘图函数的元素都显示在x轴上)图表?

pre $ lt; code> plt.plot(xValues,meanWeekdayArrivalCounts,'k-')

我希望列表xValues中的所有值都显示在图上。默认情况下,只显示0,10,20,30,40,50。



解决方案

只需添加 plt.xticks(xValues)到你的代码。鉴于图形中的点数,标签可能会混乱。

如果您使用 ax.set_xticks(xValues,minor = True)将它们设置为轴对象,则可以将它们显示为小勾号


Could someone please guide me on how should I make sure that all ticks (or maybe a better way to specify will be to say all elements in the list passed to plot function) are displayed on the x axis when using matplotlib to plot graphs?

plt.plot(xValues, meanWeekdayArrivalCounts, 'k-')

I want all the values in the list xValues to show up on the graph. By default, only, 0, 10, 20, 30, 40, 50 show up.

解决方案

Simply add plt.xticks(xValues) to your code. Given the number of points in your graph, the labels might clutter.

You could display them as minor ticks if you set them on the axes object with ax.set_xticks(xValues, minor=True).

这篇关于Matplotlib:使范围内的所有值显示在x轴上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆