How to display all label values in matplotlib?

*爱你&永不变心* 提交于 2019-12-18 03:54:34

问题


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()

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.

P.S. My x axis is not sorted, should display as it shows.


回答1:


Add this:

ax1.set_xticks(np.arange(len(x)))

To your code before your ax1.set_xticklabels(x) call. Is that what you're looking for?



来源:https://stackoverflow.com/questions/26131822/how-to-display-all-label-values-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!