如何在matplotlib中显示所有标签值?

Kev*_*vin 18 python graph matplotlib axis-labels

我有两个列表,当我使用以下代码绘图时,x轴最多只显示12(最大值为15).我可以知道如何将x列表中的所有值显示到x轴?提前致谢.

x = [4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3]
y = [10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160]
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(np.arange(len(x)), y, 'o')
ax1.set_xticklabels(x)
plt.show()
Run Code Online (Sandbox Code Playgroud)

如果我在set_xticklabels函数中设置minor = True ,它会显示所有x = 2,4,6,8,..,16 ......但我想要所有值.

PS我的x轴未排序,应显示如图所示.

far*_*rth 36

添加这个:

ax1.set_xticks(np.arange(len(x)))
Run Code Online (Sandbox Code Playgroud)

ax1.set_xticklabels(x)致电之前的代码.这就是你要找的东西吗?