Unable to share x-axis when using matplotlib.figure.Figure

Hello,

I’m trying to use the seaborn.objects interface to create a multi-plot figure. I want the three plots to share the x-axis. However, I’m having difficulty figuring out how to get them to do so.

Here is the code I’m using:

f = mpl.figure.Figure(figsize=(20, 9))
sf1, sf2, sf3 = f.subfigures(3, 1)
(
    so.Plot(core_df, x="depth_cm", y="l_star_moving_avg", group="section_no")
    .add(so.Line(color="black"))
    .label(x="Depth (cm)", y="L* Channel")
    .limit(x=(0, 827.4))
    .scale(
        x=so.Continuous().tick(every=20)
    )
    .theme(theme_settings)
    .on(sf3)
    .plot()
)
(
    so.Plot(core_df, x="depth_cm", y="a_star_moving_avg", group="section_no")
    .add(so.Line(color="black"))
    .label(x="Depth (cm)", y="a* Channel")
    .limit(x=(0, 827.4))
    .scale(
        x=so.Continuous().tick(every=20)
    )
    .theme(theme_settings)
    .on(sf2)
    .plot()
)
(
    so.Plot(core_df, x="depth_cm", y="b_star_moving_avg", group="section_no")
    .add(so.Line(color="black"))
    .label(x="Depth (cm)", y="b* Channel")
    .limit(x=(0, 827.4))
    .scale(
        x=so.Continuous().tick(every=20)
    )
    .theme(theme_settings)
    .on(sf1)
    .plot()
)

I figure I’d be placing sharex=True somewhere, but I can find where that would be.

Thanks!

I don’t know about the seaborn side of things, but from Matplotlib, you can initiate sharing after the fact with matplotlib.axes.Axes.sharex — Matplotlib 3.9.2 documentation