Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "xticks" work on the figure but "set_xticks" not on the axis?

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
like image 968
lordy Avatar asked Aug 14 '18 14:08

lordy


1 Answers

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])
like image 118
DavidG Avatar answered Oct 12 '22 22:10

DavidG