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:
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.
Activity
anntzer commented on Jun 6, 2024
Unsharing was always problematic and not really actually supported; see e.g. the discussions at #1312 and #9923.
rdg-netra commented on Jun 6, 2024
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.
timhoffm commented on Dec 13, 2025
For now axis unsharing is officially not supported.