Hiding axis text in matplotlib plots Hiding axis text in matplotlib plots python python

Hiding axis text in matplotlib plots

Instead of hiding each element, you can hide the whole axis:


Or, you can set the ticks to an empty list:


In this second option, you can still use plt.xlabel() and plt.ylabel() to add labels to the axes.

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.

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