Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add more labels to the x axis python matplotlib [closed]

this is my original graph: enter image description here

I didn't change the xticklabels or anything, I only did plot(x,y), the labels are automatically generated according to the x values.

However I want to change the x label to [0,24,48,72....480,504]

This is what I did

ax.plot(x1,y1)

xlabel =[]
xinterval = np.arange(0,504,24) 
ax.set_xticks=(xinterval)
ax.set_xticklabels(xinterval)

And the result is: enter image description here

which is obviously wrong, could anyone help?

like image 936
manxing Avatar asked Jun 09 '26 03:06

manxing


1 Answers

You have a typo; it's supposed to be ax.set_xticks(xinterval), without the =.

No need for the set_xticklabels command.

like image 157
Lior Avatar answered Jun 11 '26 17:06

Lior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!