Removing axis ticks from one subplot

Viewed 752

I'm having trouble removing axis labels from only one subplot. Everything I try removes both. My goal is to keep ticks on the left plot, but remove them on the right. Here's what I've tried.

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.gridspec as gridspec

#some data.
x = np.arange(1,11)

fig = plt.figure(1)
grid = gridspec.GridSpec(1, 2)
grid.update(hspace=0)


plt0 = plt.subplot(grid[0,0])
plt.plot(x,x)

plt1 = plt.subplot(grid[0,1], sharey =plt0)
#The line below removes ticks from both subplots.
plt1.set_yticks([])
plt.plot(x,2*x)

Any help would be greatly appreciated.

1 Answers

You can use labelleft=False to turn off the tick labels and length=0 to hide the tick marks.

plt1.tick_params(labelleft=False, length=0)

plt.plot(x, 2*x)

enter image description here

Related