How to display all label values ​​in matplotlib?

I have two lists, when I draw with the following code, the x axis only shows up to 12 (max - 15). Can I find out how to show all the values ​​in the x list along the x axis? Thank you 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 set_xticklabels is set to minor = True, it shows me all x = 2,4,6,8, .., 16 ... but I want ALL the values.

PS My x axis is not sorted, it should be displayed as it shows.

+6
source share
1 answer

Add this:

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

In your code before calling ax1.set_xticklabels(x) . Is this what you are looking for?

+19
source

Source: https://habr.com/ru/post/976081/


All Articles