You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
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
The text was updated successfully, but these errors were encountered: