Can't turn-off ticks when sharing axis

Hello,

Consider my simple test case:

import matplotlib.pyplot as plt

fp = plt.figure()
ax1 = fp.add_subplot(4,1,1)
ax1.plot(range(10))
ax2 = fp.add_subplot(4,1,2)
ax2.plot(range(10))
ax1.xaxis.set_major_locator (plt.NullLocator ())

ax3 = fp.add_subplot(4,1,3)
ax3.plot(range(10))

Can’t turn off

ax3.xaxis.set_major_locator (plt.NullLocator ())
ax4 = fp.add_subplot(4,1,4, sharex=ax3)
ax4.plot(range(10))

Turn-off both ax3 and ax4

#ax3.xaxis.set_major_locator (plt.NullLocator ())

plt.show()

When I share x-axis in between two plots I can’t turn-off one axis’ major ticks. Depends on the location of the function call it either turn nothing or all. Is it intended or a mal-functioning? (Shared axis is for my screen view, I can live without it by turning off sharex option since it won’t make any difference for the final saved figures.)

Thanks.

···


Gökhan

The standard trick is to make the ticklabels on one axes invisible

for label in ax.get_xticklabels():
     label.set_visible(False)

JDH

···

On Apr 22, 2010, at 12:28 PM, Gökhan Sever <gokhansever@...287...> wrote:

Hello,

Consider my simple test case:

import matplotlib.pyplot as plt

fp = plt.figure()
ax1 = fp.add_subplot(4,1,1)
ax1.plot(range(10))
ax2 = fp.add_subplot(4,1,2)
ax2.plot(range(10))
ax1.xaxis.set_major_locator (plt.NullLocator ())

ax3 = fp.add_subplot(4,1,3)
ax3.plot(range(10))
# Can't turn off
ax3.xaxis.set_major_locator (plt.NullLocator ())
ax4 = fp.add_subplot(4,1,4, sharex=ax3)
ax4.plot(range(10))
# Turn-off both ax3 and ax4
#ax3.xaxis.set_major_locator (plt.NullLocator ())

plt.show()

When I share x-axis in between two plots I can't turn-off one axis' major ticks. Depends on the location of the function call it either turn nothing or all. Is it intended or a mal-functioning? (Shared axis is for my screen view, I can live without it by turning off sharex option since it won't make any difference for the final saved figures.)

Thanks John, This answer seems familiar to me :slight_smile: You have caught my intention correctly --not completely clearing the x-axis but rather turning-off the labels.

Your trick works independent from sharing state of an x-axis.

Alternatively, I use ax.xaxis.set_ticklabels ("") to clear tick-labels when I don’t share the axis.

···

On Thu, Apr 22, 2010 at 7:38 PM, John Hunter <jdh2358@…83…287…> wrote:

The standard trick is to make the ticklabels on one axes invisible

for label in ax.get_xticklabels():

label.set_visible(False)

JDH


Gökhan