Unable to remove yticks from pyplot subplots
Unable to remove yticks from pyplot subplots
I created a subplot using matplotlib.pyplot. Even as I set the tick labels to empty using:
plt.xticks([ ])
plt.yticks([ ])
How can I remove these? I am new to Python and any help on the matter is appreciated.

2 Answers
2
Your figure has many subplots in it. You need to remove the ticks in each axis object of each subplot (or at least the ones you done want to appear). This can be done like this:
import matplotlib.pyplot as plt
ax1 = plt.subplot(321) # 1st subplot in 3-by-2 grid
ax1.plot(...) # draw what you want
ax1.set_xticks(, ) # note you need two lists one for the positions and one for the labels
ax1.set_yticks(, ) # same for y ticks
ax2 = plt.subplot(321) # 2nd subplot in the same grid
# do the same thing for any subplot you want the ticks removed
If you want the whole axis (borders, ticks and labels) removed you can just do this:
ax1.axis('off')
However I'd suggest typing plt.tight_layout(). It might fix your problem without requiring you to remove the ticks.
plt.tight_layout()
You can use the plt.tick_params option to fine tune your plots:
plt.tick_params(axis='both', which='both', right=False, left=False, top=False, bottom=False)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
HI Thanks for you solution. @Carlo, I realized since I was using log scale in the vertical, those spurious ticks are the minor ticks. Hence I shut them off using plt.minorticks_off(). Thanks a lot.
– ag1992
Aug 26 at 4:12