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
{{ message }}
Repository navigation
[Bug]: Calling axes.clear() on a shared y or x-axis issues an unexpected warning with log scale #30159
I somehow created a plot in unorthodox order, i.e. first plot some data in the second column, then in the first one. To generate my plots, I call a method that automatically
clears the axes
sets the scale
sets the limits
plots the data
In this case two warnings are issued. The code of the minimal example reproduces this behavior. When changing it to the second variant in the code block (first plotting the first column, then the second column) the issue disappears.
FutureWarning: Attempt to set non-positive ylim on a log-scaled axis will be ignored.
FutureWarning: Attempting to set identical low and high ylims makes transformation singular; automatically expanding.
It seems like the master and follower plots have become parent and children plots. I think it would be better if when we call ax.clear() on any of the plots we can prevent it from changing the scale and limits from defaulting and this will result in the plots being tightly bounded to each when shared
clear() semantics for shared Axes is not well defined. See also #28851 (comment).
As an implementation detail, sharing is implemented asymmetrically.
In [1]: fig, axs=plt.subplots(1, 2, sharey=True)
In [2]: axs[0]._shareyisNoneOut[2]: TrueIn [3]: axs[1]._shareyisaxs[0]
Out[3]: True
The unclear semantics results in different behaviors on both Axes:
axs[1].clear() leaves the scale and axes limits unchanged
axs[0].clear() resets the scale and axes limits on axs[0]. It leaves the scale on axs[1] but tries to propagate the reset axes limits from 1 to 2 causing the warning.
The quick fix for more consistency would be to make axs[0].clear() also leave scale and limits unchanged. This would be more consistent, but not necessarily a desired behavior (see #28851 (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'].
Activity
fwitte commentedon Jun 10, 2025
To add:
With a grid of plots, the issue only appears, when the very first axes (top left) is cleared.
No warning issued:
Warning issued:
jklymak commentedon Jun 10, 2025
This does seem to be a bug in that the yscale is shared in the second case, but not in the first.
rcomer commentedon Jun 10, 2025
Maybe caused by #27825
mrinalcodez commentedon Jul 21, 2025
It seems like the master and follower plots have become parent and children plots. I think it would be better if when we call ax.clear() on any of the plots we can prevent it from changing the scale and limits from defaulting and this will result in the plots being tightly bounded to each when shared
timhoffm commentedon Jul 21, 2025
clear()semantics for shared Axes is not well defined. See also #28851 (comment).As an implementation detail, sharing is implemented asymmetrically.
The unclear semantics results in different behaviors on both Axes:
axs[1].clear()leaves the scale and axes limits unchangedaxs[0].clear()resets the scale and axes limits onaxs[0]. It leaves the scale onaxs[1]but tries to propagate the reset axes limits from 1 to 2 causing the warning.The quick fix for more consistency would be to make
axs[0].clear()also leave scale and limits unchanged. This would be more consistent, but not necessarily a desired behavior (see #28851 (comment)).timhoffm commentedon Nov 16, 2025
I think a reasonable incremental improvement would be to remove the
Axes._sharex/ystate. It's only used in very few places and can more reasonably be handled via the grouperAxes._shared_axes['x'].MNT: Improve Grouper
MNT: Improve Grouper
MNT: Improve Grouper