Python Matplotlib:使范围内的所有值都显示在 x 轴上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17102329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Matplotlib: Make all values in range show up on x axis
提问by Shubham Goyal
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?
有人可以指导我如何确保在使用 matplotlib 绘制图形时所有刻度(或者更好的指定方法是说传递给 plot 函数的列表中的所有元素)都显示在 x 轴上?
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.
我希望列表 xValues 中的所有值都显示在图表上。默认情况下,仅显示 0、10、20、30、40、50。


回答by Rutger Kassies
Simply add plt.xticks(xValues)to your code. Given the number of points in your graph, the labels might clutter.
只需添加plt.xticks(xValues)到您的代码中。鉴于图表中的点数,标签可能会混乱。
You could display them as minor ticks if you set them on the axes object with ax.set_xticks(xValues, minor=True).
如果您将它们设置在轴对象上,则可以将它们显示为小刻度ax.set_xticks(xValues, minor=True)。
回答by Raghu Ram
use this.
用这个。
fig = plt.figure(figsize=(10,8))
plt.xticks(np.arange(min(x), max(x)+1, 1.0))

