Home > Blockchain >  How do I remove labels from one axis in a subplot?
How do I remove labels from one axis in a subplot?

Time:04-08

I am using Python 3.9 on MacOS. Shortly, I have to make a plot with 4 subplots, and they share axis. The code looks like this:


#take some data
gs = gridspec.GridSpec(2, 2, height_ratios = [3, 1])
ax0 = plt.subplot(gs[0])

#plot data, make legend, etc.

ax2 = plt.subplot(gs[2], sharex = ax0)

#plot data, make legend, etc.

#take more data

ax1 = plt.subplot(gs[1], sharey = ax0)

#plot data, make legend, etc.

ax3 = plt.subplot(gs[3], sharex = ax1, sharey = ax2)

#plot data, make legend, etc.

plt.show()

As you can see, some plots share an axis with each other. The problem is that on the x-axis everything is fine, while it is not on the y-axis (see picture). Getting to the point: how can I remove the numbers on the vertical axis of the right plot but not on the left? I've seen many posts in which the problem was solved with things like

ax.set_yticklabels([])

but that removes the numbers from the left plot as well.

enter image description here

CodePudding user response:

Try this:

ax1.tick_params('y', labelleft=False)
  • Related