Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ENH]: Be able to ignore specific plots when autoscaling axes #29634

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
edbennett opened this issue Feb 17, 2025 · 6 comments
Open

[ENH]: Be able to ignore specific plots when autoscaling axes #29634

edbennett opened this issue Feb 17, 2025 · 6 comments

Comments

@edbennett
Copy link

Problem

When building up scatter or error bar plots of data, I frequently want to overlay a fitting function or other set of lines/bands. The latter need to extend for the full width/height of the Axes. If I'm using autoscaling, this doesn't happen because the scale adjusts to leave a margin around the new plots.

Currently, to avoid this, I need to do something like:

xlim, ylim = ax.get_xlim(), ax.get_ylim()
plt.plot(...) # Add lines
ax.set_xlim(xlim)
ax.set_ylim(ylim)

This means I am constrained in how I order my code—I have to have all my data contributing to autoscaling present before I add any fit lines. (This gets more complicated when I am working with multiple Axes with sharex or sharey.)

Example of what I might be looking for:

Image

Example of what I currently get without the workaround above:

Image

Proposed solution

Ideally, have a new keyword argument on plot and friends, something like use_in_autoscale: bool = True. When True, the object generated by plot contributes to the axis limit computations as currently; when False, then it is ignored in these computations.

@anntzer
Copy link
Contributor

anntzer commented Feb 17, 2025

See #15595 and linked issues.

@edbennett
Copy link
Author

I searched for a while before raising but clearly used the wrong keywords, as I didn't turn up those. Thanks for pointing me at them!

@rcomer
Copy link
Member

rcomer commented Feb 17, 2025

Specifically for straight lines, you can use axline.

@edbennett
Copy link
Author

edbennett commented Feb 17, 2025

Thanks @rcomer, I wasn't aware of axline—that plus axhspan do cover a decent amount of my needs, but not all of them, as sometimes I need to use fill_between with curves.

@jklymak
Copy link
Member

jklymak commented Feb 18, 2025

I dont' see any reason something like #15595 could not go through. It just needs someone interested in the capability to implement it.

@timhoffm
Copy link
Member

The current architecture is somewhat messy, we probably need to clean that up first, but it should not be too hard #15595 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants