Python 如何让 matplotlib 显示所有 x 坐标?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28506907/
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
How to make matplotlib show all x coordinates?
提问by jsguy
For example in the following code:
例如在以下代码中:
import numpy as np
import matplotlib.pyplot as plt
N = 10
x = [1,2,3,4,5,6,7,8,9,10]
y = np.random.rand(N)
plt.scatter(x, y)
plt.show()
I get the following plot
我得到以下情节
as you can see, in the x axis only the even values appear. How to force matplotlib to show all values, that is 1 2 3 4 5 6 7 8 9 10?
如您所见,在 x 轴上仅出现偶数值。如何强制 matplotlib 显示所有值,即 1 2 3 4 5 6 7 8 9 10?
采纳答案by BrenBarn
Use plt.xticks(x)
. See the documentation.
使用plt.xticks(x)
. 请参阅文档。
Note that using only the input values for ticks will usually be confusing to a viewer. It makes more sense to use evenly spaced ticks.
请注意,仅使用刻度的输入值通常会使查看者感到困惑。使用均匀间隔的刻度线更有意义。