Skip to content

[MNT]: Consolidate axis sharing logic #32520

Open

Description

@timhoffm

Summary

Sharing information is stored redundantly:

  • in the grouper class attribute Axes._shared_axes['x']. The grouper stores the shared axes in a list without a hierarchy.
  • in the _sharex attribute of Axes. This is asymmetic in that the only one of the Axes gets the _sharex attribute set, resulting in a parent-child relation.

Proposed fix

From #30159 (comment)

I think a reasonable incremental improvement would be to remove the Axes._sharex/y state. It's only used in very few places and can more reasonably be handled via the grouper Axes._shared_axes['x'].

Still to be clarified: Do we need the parent-child relation in any way? - From a quick look I don't think so.

Activity

  1. changed the title [-][MNT]: Consolidate sharing logic[/-] [+][MNT]: Consolidate axis sharing logic[/+] on Oct 22, 2026
  2. tamrind69 commented on Oct 30, 2026

    @tamrind69

    Hi @timhoffm
    I'm new here and i had started with understanding the axes functionality and found this issue relevant.
    I was looking at all places where we're using _sharex and _sharey , I have some questions to help myself better understand. I've compiled all existing occurences and proposed change along with any doubts i have.

    1 in axes\_base.py in the _AxesBase class

    inside sharex() (similar for sharey())

    if self._sharex is not None and other is not self._sharex:
                raise ValueError("x-axis is already shared")
            self._shared_axes["x"].join(self, other)
            self._sharex = other

    we are enforcing an assymetric relation here but it is not serving any purpose. We could very well use the grouper DSU to just join them.


    in _clear()

    if self._sharex is not None:
                self.xaxis.set_visible(xaxis_visible)
                self.patch.set_visible(patch_visible)
            if self._sharey is not None:
                self.yaxis.set_visible(yaxis_visible)
                self.patch.set_visible(patch_visible)

    we are restoring previous visibility config if there is axis sharing , imo this is equivalent to checking if it has any siblings using the grouper.
    But even if _sharex = None , there still can be shared axis but being refernced by the other axes obj's _sharex attr.
    I dont think this is intended but maybe im not understanding correctly.

    2 in mpl_toolkits\parasite_axes.py'

    in HostAxesBase class

    def _remove_any_twin(self, ax):
            self.parasites.remove(ax)
            restore = ["top", "right"]
            if ax._sharex:
                restore.remove("top")
            if ax._sharey:
                restore.remove("right")
            self.axis[tuple(restore)].set_visible(True)
            self.axis[tuple(restore)].toggle(ticklabels=False, label=False)

    the _sharex and _sharey checks are equivalent to checking whether the host exists as a sibling by ax._shared_axes["x"/"y"].get_siblings(ax) .

    I apologize for any naiveness on my part. I'd like to work on this if possible.

  3. tamrind69 commented on Nov 2, 2026

    @tamrind69

    Hi @timhoffm . Apologies for another ping but is this open to work on? I'd like to submit a pr
    thankyou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions