Hi Everyone,
I have several subplots in one figure, and I'm trying to dynamically
display different subplots depending on user input. Everything works
fine with the set_visible command, except that I'm running into a
problem with shared axes. Basically, I'd like to be able to choose to
display subplots (211) and (212) with optionally shared x-axes, and it
looks like I either need to find a way to tell add_subplot to not
delete overlapping axes *or* to be able to dynamically set axes to
share an x-axis
My first thought was to create two sets of overlapping axes and set
one pair invisible, something like this:
f = figure(0)
ax1_noshare = f.add_subplot(211)
ax2_noshare = f.add_subplot(212)
ax1_share = f.add_subplot(211)
ax2_share = f.add_subplot(212, sharex=ax1_share)
# more code here
if show_shared:
ax1_noshare.set_visible(False)
ax1_noshare.set_visible(False)
ax1_share.set_visible(True)
ax1_share.set_visible(True)
#etc
However, the second set of add_subplot(211) calls (to create ax1_share
and ax2_share) delete the overlapping axes defined just above, so when
I go to set the non-shared axes visible, I get a blank figure.
I could, of course, change my code such that I can just optionally set
ax2 to share ax1's x-axis, but I'd need a function like:
ax2.set_shared_axis(sharex=ax1)
which doesn't appear to exist.
So my question is, Is it possible to either specify that add_subplot
should not delete overlapping axes, or to set a shared axis after the
axis has already been created?
Thanks,
Michael