[英]How to make matplotlib show all x coordinates?
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. 如您所见,在x轴上只显示偶数值。 How to force matplotlib to show all values, that is 1 2 3 4 5 6 7 8 9 10?
如何强制matplotlib显示所有值,即1 2 3 4 5 6 7 8 9 10?
Use plt.xticks(x)
. 使用
plt.xticks(x)
。 See the documentation . 请参阅文档 。
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.
使用均匀间隔的刻度更有意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.