Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove xticks in a matplotlib plot?

I have a semilogx plot and I would like to remove the xticks. I tried:

plt.gca().set_xticks([]) plt.xticks([]) ax.set_xticks([]) 

The grid disappears (ok), but small ticks (at the place of the main ticks) remain. How to remove them?

like image 911
Vincent Avatar asked Oct 21 '12 13:10

Vincent


People also ask

How do you get rid of an axis tick?

To remove the ticks on both the x-axis and y-axis simultaneously, we can pass both left and right attributes simultaneously setting its value to False and pass it as a parameter inside the tick_params() function. It removes the ticks on both x-axis and the y-axis simultaneously.


2 Answers

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 plt plt.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 off plt.show() plt.savefig('plot') plt.clf() 

enter image description here

like image 104
John Vinyard Avatar answered Sep 21 '22 19:09

John Vinyard


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') 
like image 30
Martin Spacek Avatar answered Sep 23 '22 19:09

Martin Spacek