Skip to content

[Bug]: removing already extablished axis sharing #28345

Closed as not planned
Closed as not planned

Description

@rdg-netra

Bug summary

I have not been able to find a supported method for removing axis sharing that has already been established. At least, not without removing and re-creating the axis.

In older versions of matplotlib, it was possible to do:
ax1.get_shared_x_axes().remove(ax2)
but with the new axis grouper API, this is no longer possible ('GrouperView' object has no attribute 'remove').

There does seem to be a workaround using an internal variable:
ax1._shared_axes['x'].remove(ax2)

I would suggest that a natural way to support removing all axis sharing might be a method:

ax.set_shared_xaxis(None)

or possibly

ax.sharex(None)

Code for reproduction

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
ax1.plot([0, 1, 2], [1, 2, 3])
ax2.plot([0, 1, 2], [3, 2, 1])

ax1.set_shared_xaxis(None)

plt.show()

Actual outcome

AttributeError: 'Axes' object has no attribute 'set_shared_xaxis'.

Expected outcome

Axis sharing should not be enabled.

Additional information

No response

Operating system

No response

Matplotlib Version

3.8.2

Matplotlib Backend

No response

Python version

3.10.13

Jupyter version

No response

Installation

conda

Activity

  1. anntzer commented on Jun 6, 2024

    @anntzer
    Contributor

    Unsharing was always problematic and not really actually supported; see e.g. the discussions at #1312 and #9923.

  2. rdg-netra commented on Jun 6, 2024

    @rdg-netra
    Author

    Thanks for that. I have looked through the discussion in the issues mentioned. I can see that it is indeed more tricky than it might at first seem.

    My situation is that I have an interactive application with two figures where there are two possible modes of interaction with the data. I need to be able to toggle fairly quickly between modes. In one case, the x axis needs to be shared, the other not. It has been working for a long time with older matplotlib versions, so this issue means I either can't upgrade or need to use the internal variable workaround. Removing and re-creating the whole figure every time is really not something I want to do.

    My reading of issue #15287 is that there was an intention to solve the easier problem, i.e. just allow clearing all sharing for an axis, rather than removing specific shares in a possibly complicated tree. In my case this would be fine since I don't have any complicated sharing structure. However, although the PR seemed to be accepted I couldn't really follow what happened here and if there is a supported way to do what I need.

    If anyone has a better handle on situation or other suggestions that would be helpful.

    If there really is no supported way to do it, I might suggest that the documentation for matplotlib.axes.Axes.sharex and Figure.subplots sharex argument should have a warning explaining not possible to remove sharing after those methods have been used.

  3. timhoffm commented on Dec 13, 2025

    @timhoffm
    Member

    For now axis unsharing is officially not supported.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions