This should work but it does not?
plt.figure()
plt.plot(x)
plt.xticks(range(4), [2, 64, 77, 89]) # works
f, ax = plt.subplots(nrows=2, ncols=2)
ax[0, 0].plot(x)
ax[0, 0].set_xticks(range(4), [2, 64, 77, 89]) # does not work
When using the object orientated API (as in your second example), the functions to set the tick locations and the tick labels are separate - ax.set_xticks
and ax.set_xticklabels
. Therefore, you will need:
f, ax = plt.subplots(nrows=2, ncols=2)
ax[0, 0].plot(x)
ax[0, 0].set_xticks(range(4))
ax[0, 0].set_xticklabels([2, 64, 77, 89])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With