Hint how to set axis limits with margins #25962
Open
+10
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR summary
I recently came across a use case where I wanted to manually tweak axis limits, but also apply the margins which are added when autoscaling. It took me a while to figure out how to do this in an elegant way that would avoid computing the margins manually (in order to defer to Matplotlib for this): by modifying the
Axes.dataLim
bounding box and re-applying autoscaling. SinceAxes.set_{x,y}lim
is the most straightforward starting point when considering axis limits tweaks, I think it would make sense to document this approach there, as a helpful hint to anyone trying to do something similar.I understand this might not be wanted for a variety of reasons, or perhaps you'd rather put this somewhere else than in the API docs for the
Axes.set_{x,y}lim
functions, or perhaps you'd just phrase it differently. I just wanted to start the conversation over a concrete suggestion; that's why a PR instead of just opening an issue. I do think that it would be useful to document this somewhere, preferably in a way that's reachable from theAxes.set_{x,y}lim
docs, but I'm not too particular about the details and would be happy to take suggestions about places which might be a better fit.PR checklist