Skip to content

Hint how to set axis limits with margins #25962

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dlukes
Copy link

@dlukes dlukes commented May 24, 2023

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. Since Axes.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 the Axes.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

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@timhoffm
Copy link
Member

timhoffm commented Jun 1, 2023

Thanks for the contribution.

A textual description in the docstring is quite hard to follow. I think there are two alternatives:

Likely the right one: Create an example.

Maybe (but likely not - that would need more thorough thought and discussion): Expand the set_xlim() API with margin capability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

4 participants