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
ax.transData
does not honorxlim
andylim
. The document athttps://matplotlib.org/stable/users/explain/artists/transforms_tutorial.html#data-coordinates seems to suggest that data limits are updated automatically when new data are added to the axes, but it's not the case, which breaksax.transData
, since it reads an old version of data limits.
Code for reproduction
frommatplotlibimportpyplotaspltfig,ax=plt.subplots(figsize=(10,10),dpi=100)print(f"fig size:{fig.get_size_inches()*fig.dpi}")ax.plot([0,10], [0,10],'o')print(f"(10, 10) in data coordinates:{ax.transData.transform((10,10))}")ax.set_xlim(ax.get_xlim())# just ax.get_xlim() or ax.viewLim or ax.autoscale_view() is enoughax.set_ylim(ax.get_ylim())print(f"(10, 10) in data coordinates:{ax.transData.transform((10,10))}")
Actual outcome
fig size: [1000. 1000.]
(10, 10) in data coordinates: [7875. 7810.]
(10, 10) in data coordinates: [864.77272727 845. ]
Expected outcome
fig size: [1000. 1000.]
(10, 10) in data coordinates: [864.77272727 845. ]
(10, 10) in data coordinates: [864.77272727 845. ]
Additional information
The wording fromhttps://matplotlib.org/stable/users/explain/artists/transforms_tutorial.html#data-coordinates suggests that data limits are updated automatically when new data are added, but it requires manual trigger ofset_xlim
/set_ylim
(orget_xlim
/get_ylim
which callsax.viewLim
).
This is quite confusing. I would hope that either the documentation is updated to notify the user to explicitly update the data limits, or even better, lettransData
/transLimits
always use the latest data limits.
Operating system
No response
Matplotlib Version
3.8.3
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None