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

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

问题描述

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

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

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

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.

推荐答案

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

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

如果您使用 ax.set_xticks(xValues, minor=True) 在轴对象上设置它们,您可以将它们显示为次要刻度.

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天全站免登陆