Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
When switching an axis to a new unit, the unit converter can propose new default limits (AxisInfo.default_limits), which are applied if the user did not manually set limits themselves. However, detection of "whether the user manually set limits themselves" is brittle: if the user set the limits to (0, 1), then it will appear as if they didn't do anything, and the unit default_limits will be applied.
Code for reproduction
frompylabimport*rcdefaults()rcParams["date.converter"]="concise"rcParams["date.epoch"]="2000-01-01T00:00:00"axs=figure(layout="constrained").subplots(3)axs[0].text(.5,.5,"no xlim manually set",transform=axs[0].transAxes,ha="center")axs[0].xaxis_date()axs[1].text(.5,.5,"xlim manually set to (0, 1)",transform=axs[1].transAxes,ha="center")axs[1].set_xlim(0,1)axs[1].xaxis_date()axs[2].text(.5,.5,"xlim manually set to (0, 2)",transform=axs[2].transAxes,ha="center")axs[2].set_xlim(0,2)axs[2].xaxis_date()show()
Actual outcome
The case of datetimes is made slightly more complicated by the fact that default_limits is 1970-01-01 to 1970-01-02 which happens to also be (0, 1) with the default epoch, but we can set the epoch to something else (here 2000-01-01) to showcase the issue.
Here, if no xlim was manually setor if xlim was manually set to (0, 1), then AxisInfo.default_limits gets applied, but not if xlim was manually set to (0, 2).
In practice, this occurs because the choice of whether to apply AxisInfo.default_limits relies on Bbox.mutatedx/Bbox.mutatedy, which performs a check on the value of the current limits.
Expected outcome
Manually setting limits should disable AxisInfo.default_limits. Iguess(?) a reasonable way to check that is to see whether Axes.get_autoscalex_on/get_autoscaley_on is Trueand there is no data participating in the autoscaling? (Or we could add yet another flag, but I thing autoscaleness is a close enough concept to be reused here.)
(Alternatively, we could say that AxisInfo.default_limits must always be equal to (0, 1) (after conversion), but in that case we should just get rid of AxisInfo.default_limits as a customization point...)
Additional information
No response
Operating system
macOS
Matplotlib Version
3.8.0.dev676+g5a34696d71
Matplotlib Backend
any
Python version
3.11
Jupyter version
ENOSUCHLIB
Installation
git checkout