Hiding axis text in matplotlib plots
Solution 1:
Instead of hiding each element, you can hide the whole axis:
frame1.axes.get_xaxis().set_visible(False)
frame1.axes.get_yaxis().set_visible(False)
Or, you can set the ticks to an empty list:
frame1.axes.get_xaxis().set_ticks([])
frame1.axes.get_yaxis().set_ticks([])
In this second option, you can still use plt.xlabel()
and plt.ylabel()
to add labels to the axes.
Solution 2:
If you want to hide just the axis text keeping the grid lines:
frame1 = plt.gca()
frame1.axes.xaxis.set_ticklabels([])
frame1.axes.yaxis.set_ticklabels([])
Doing set_visible(False)
or set_ticks([])
will also hide the grid lines.
Solution 3:
If you are like me and don't always retrieve the axes, ax
, when plotting the figure, then a simple solution would be to do
plt.xticks([])
plt.yticks([])