Tying X axes information together in multiple subplots?

I'm making a set of plots (a strip chart) stacked on top of each other,
all sharing the same X axis (time).

So far it appears that to get the X axis of each Subplot to match I have
to set its properties independently.

Is there some way to tie them all together so that a user can set the
properties of one and have it propagate? I'm particularly concerned
about tick marks and the X grid lines; I only want to show tick labels
on the bottom-most Subplot.

I suppose one possibility is to create some kind of object on which I
can call Subplot.xaxis methods and have it apply those changes to all
the Subplots. Has anyone done this?

-- Russell

Russel, maybe this example might help?

http://matplotlib.sourceforge.net/examples/pylab_examples/shared_axis_demo.html

There are also some more advanced subplot layout methods available called axis_grid1 in the mpl_toolkits.

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html

I hope this helps!

Ben Root

···

On Fri, Sep 24, 2010 at 12:30 PM, Russell E. Owen <rowen@…3288…> wrote:

I’m making a set of plots (a strip chart) stacked on top of each other,

all sharing the same X axis (time).

So far it appears that to get the X axis of each Subplot to match I have

to set its properties independently.

Is there some way to tie them all together so that a user can set the

properties of one and have it propagate? I’m particularly concerned

about tick marks and the X grid lines; I only want to show tick labels

on the bottom-most Subplot.

I suppose one possibility is to create some kind of object on which I

can call Subplot.xaxis methods and have it apply those changes to all

the Subplots. Has anyone done this?

– Russell

In article
<AANLkTinTBfS8OWjeLHopXS9x6dxeNwYKzqFEhVqR5U+=@mail.gmail.com>,

> I'm making a set of plots (a strip chart) stacked on top of each other,
> all sharing the same X axis (time).
>
> So far it appears that to get the X axis of each Subplot to match I have
> to set its properties independently.
>
> Is there some way to tie them all together so that a user can set the
> properties of one and have it propagate? I'm particularly concerned
> about tick marks and the X grid lines; I only want to show tick labels
> on the bottom-most Subplot.
>
> I suppose one possibility is to create some kind of object on which I
> can call Subplot.xaxis methods and have it apply those changes to all
> the Subplots. Has anyone done this?
>
> -- Russell
>
>
Russel, maybe this example might help?

http://matplotlib.sourceforge.net/examples/pylab_examples/shared_axis_demo.htm
l

There are also some more advanced subplot layout methods available called
axis_grid1 in the mpl_toolkits.

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html

I hope this helps!

Ben Root

Thank you. sharex was just what I was looking for.

I was pleasantly surprised I could hide the x axis labels on the upper
subplots using the following code:
        for subplot in self.subplotArr[0:-1]:
            # can't find API equivalent of pylab.setp so...
            for ticklabel in subplot.get_xticklabels():
                ticklabel.set_visible(False)
since it's a strip chart and new X ticks are constantly being created as
time advances. Thank heavens it doesn't show labels on the new ones.

I also tried axis_grid1 but was unable to get plots, and since the other
technique is working and more backward-compatible I'm happy to stick to
that.

Regards,

-- Russell

···

Benjamin Root <ben.root@...1304...> wrote:

On Fri, Sep 24, 2010 at 12:30 PM, Russell E. Owen > <rowen@...2756...> wrote:

In article

<AANLkTinTBfS8OWjeLHopXS9x6dxeNwYKzqFEhVqR5U+=@mail.gmail.com>,

I’m making a set of plots (a strip chart) stacked on top of each other,

all sharing the same X axis (time).

So far it appears that to get the X axis of each Subplot to match I have

to set its properties independently.

Is there some way to tie them all together so that a user can set the

properties of one and have it propagate? I’m particularly concerned

about tick marks and the X grid lines; I only want to show tick labels

on the bottom-most Subplot.

I suppose one possibility is to create some kind of object on which I

can call Subplot.xaxis methods and have it apply those changes to all

the Subplots. Has anyone done this?

– Russell

Russel, maybe this example might help?

http://matplotlib.sourceforge.net/examples/pylab_examples/shared_axis_demo.htm

l

There are also some more advanced subplot layout methods available called

axis_grid1 in the mpl_toolkits.

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html

I hope this helps!

Ben Root

Thank you. sharex was just what I was looking for.

I was pleasantly surprised I could hide the x axis labels on the upper

subplots using the following code:

    for subplot in self.subplotArr[0:-1]:

        # can't find API equivalent of pylab.setp so...

        for ticklabel in subplot.get_xticklabels():

            ticklabel.set_visible(False)

since it’s a strip chart and new X ticks are constantly being created as

time advances. Thank heavens it doesn’t show labels on the new ones.

Don’t know if it is useful for you or not, but there is also the .label_outer() function that will set the visibility of the axes tick labels based on which subplot they are in the figure.

I also tried axis_grid1 but was unable to get plots, and since the other

technique is working and more backward-compatible I’m happy to stick to

that.

axes_grid1 can be a little tricky to figure out at first, but once you get the knack of it, it can be a powerful feature to use in the future. However, I am glad that the other method works perfectly.

Ben Root

···

On Fri, Sep 24, 2010 at 5:47 PM, Russell E. Owen <rowen@…2756…> wrote:

Benjamin Root <ben.root@…1304…> wrote:

On Fri, Sep 24, 2010 at 12:30 PM, Russell E. Owen > > > <rowen@…2756…> wrote:

Very nice! Much easier to read than setting each tick invisible.

Regards,

– Russell

···

On Sep 24, 2010, at 4:15 PM, Benjamin Root wrote:

On Fri, Sep 24, 2010 at 5:47 PM, Russell E. Owen <rowen@…2756…> wrote:

In article
<AANLkTinTBfS8OWjeLHopXS9x6dxeNwYKzqFEhVqR5U+=@mail.gmail.com>,

Benjamin Root <ben.root@…1304…> wrote:

On Fri, Sep 24, 2010 at 12:30 PM, Russell E. Owen > > > <rowen@…2756…> wrote:

I’m making a set of plots (a strip chart) stacked on top of each other,
all sharing the same X axis (time).

So far it appears that to get the X axis of each Subplot to match I have
to set its properties independently.

Is there some way to tie them all together so that a user can set the
properties of one and have it propagate? I’m particularly concerned
about tick marks and the X grid lines; I only want to show tick labels
on the bottom-most Subplot.

I suppose one possibility is to create some kind of object on which I
can call Subplot.xaxis methods and have it apply those changes to all
the Subplots. Has anyone done this?

– Russell

Russell, maybe this example might help?

http://matplotlib.sourceforge.net/examples/pylab_examples/shared_axis_demo.htm
l

There are also some more advanced subplot layout methods available called
axis_grid1 in the mpl_toolkits.

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html

I hope this helps!

Ben Root

Thank you. sharex was just what I was looking for.

I was pleasantly surprised I could hide the x axis labels on the upper
subplots using the following code:
for subplot in self.subplotArr[0:-1]:
# can’t find API equivalent of pylab.setp so…
for ticklabel in subplot.get_xticklabels():
ticklabel.set_visible(False)
since it’s a strip chart and new X ticks are constantly being created as
time advances. Thank heavens it doesn’t show labels on the new ones.

Don’t know if it is useful for you or not, but there is also the .label_outer() function that will set the visibility of the axes tick labels based on which subplot they are in the figure.