如何显示matplotlib中的所有标签值? [英] How to display all label values in matplotlib?
本文介绍了如何显示matplotlib中的所有标签值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个列表,当我使用下面的代码绘图时,x轴最多只显示12(最大值是15)。我可以知道如何将x列表中的所有值显示到x轴?提前致谢。
I have two lists, when I plot with the following code, the x axis only shows up to 12 (max is 15). May I know how can I show all of the values in x list to the x axis? Thanks in advance.
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()
如果我在 set_xticklabels
中设置了minor = True,函数,它显示我所有x = 2,4,6,8,...,16 ...但我想要所有的值。
If I set minor=True in the set_xticklabels
function, it shows me all x=2,4,6,8,..,16... but I want ALL values.
PS我的x轴未排序,应显示为显示。
P.S. My x axis is not sorted, should display as it shows.
推荐答案
添加此:
ax1.set_xticks(np.arange(len(x)))
在您的 ax1.set_xticklabels(x)
调用之前添加到您的代码中。那是你在找什么?
To your code before your ax1.set_xticklabels(x)
call. Is that what you're looking for?
这篇关于如何显示matplotlib中的所有标签值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文