Remove xticks in a matplotlib plot? Remove xticks in a matplotlib plot? python python

Remove xticks in a matplotlib plot?


The plt.tick_params method is very useful for stuff like this. This code turns off major and minor ticks and removes the labels from the x-axis.

Note that there is also ax.tick_params for matplotlib.axes.Axes objects.

from matplotlib import pyplot as pltplt.plot(range(10))plt.tick_params(    axis='x',          # changes apply to the x-axis    which='both',      # both major and minor ticks are affected    bottom=False,      # ticks along the bottom edge are off    top=False,         # ticks along the top edge are off    labelbottom=False) # labels along the bottom edge are offplt.show()plt.savefig('plot')plt.clf()

enter image description here


Not exactly what the OP was asking for, but a simple way to disable all axes lines, ticks and labels is to simply call:

plt.axis('off')


Alternatively, you can pass an empty tick position and label as

# for matplotlib.pyplot# ---------------------plt.xticks([], [])# for axis object# ---------------# from Anakhand May 5 at 13:08# for major ticksax.set_xticks([])# for minor ticksax.set_xticks([], minor=True)


matomo