-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: ax.transData
does not honor data limits
#28075
Comments
This has also confounded me: https://stackoverflow.com/questions/67334384 |
Calling Usually users do not need to directly query The todo here may be to make the Transformations tutorial clear that the |
I can get the rationale for why the limits are not calculated automatically. This design makes sense to me. Although the wording on the tutorial "Whenever you add data to the axes, Matplotlib updates the datalimits" is a bit confusing.
I think it might be desired to update the view limits when
My particular use case is that I want to label some numbers on a stacked bar chart, but only for the bars that are long enough so the text can fit within the bars. I cannot directly use height in the "data" coordinate because I have multiple subfigures in different scales. So I use
I figured that out after a time of debugging.
Do you think it would make sense to call matplotlib/lib/matplotlib/axes/_base.py Lines 849 to 852 in 9955a7c
Also cc: @anntzer. Before the commit 160de56, view limits are recomputed automatically after every plotting call. |
That change was intentional, as explained in the linked issues. |
I think that text was written before we made things lazier. I agree with @anntzer that the best path is to document that derived state may be inconsistent until the figure has been drawn (by rendering it to screen, saving, or |
Yes the current example is an example how not to use transforms. |
Due to this problem, I find very hard trying to create some dashes with |
How can |
If you want dashes in coordinate distance rather than points I would use The core of the issues here is that the transform objects represent computation to be done (they are a form of lazy expressions) and are mutable (e.g. |
You are very right, yes maybe the best choice is to just have either a |
Bug summary
ax.transData
does not honorxlim
andylim
. The document at https://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
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 from https://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 of
set_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, let
transData
/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
The text was updated successfully, but these errors were encountered: