-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
inconsistent autoscaling around axvlines #14651
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
Comments
I guess autoscaling should always take avhlines into account. |
fig, ax = plt.subplots()
ax.axvline(0.5, color='b', transform=ax.transAxes) I got: but the doc suggested that Am I missing something? If I wanna plot a line in the middle of a Axes, how should I do it for now rather than set xlim? |
@StevenLi-DS
You can always achieve the same with a usual line and the respective transform, hence If you want your line to be completely in axes coordinates, it would be All of this is unrelated to the original issue here. It would help to use a new issue in such cases in order to not disturb the thread of arguments in existing ones. |
Back to the original thread. I think axvline should not change the axes limits. Ever. It’s a way of annotating data, not data. If someone wants to plot a vertical line then that’s what plot is for. |
I think I would personally agree with "axvline should not change the axes limits". Related to this: #7742, which already did undergo two unsuccessful attempts to fix. |
So should it also not change limits even if plotting outside of the current limits? (I'm fine with that solution too.) |
That would be what I would expect. But maybe other users not? In particular, I think it would be a significant change to how it is handled now. |
In an ideal world it would not auto scale at all and explicitly say that in the docs |
It's probably not too hard to change that behavior with a deprecation warning (check whether the limits would change and if so warn), the only question is whether it's worth the trouble. |
not sure I agree with that. If the user plots this line, there's some intent behind it and it's most likely undesired if the line does not show up. Example: Plot some relative values. Values larger than 1 represent data that got larger, values below 1 got smaller. It can be reasonable to |
I'd argue in that case the user can specify those important limits manually. My conceptualization of I appreciate other folks might conceptualize it differently, so we should decide if it autoscales (in x) or not, but not do something that is half way. |
If I plot a vertical line at x=0.5, I'd expect 0.5 to be considered when automatically determining X plot limits. I would not expect to need to manually tell matplotlib to include this. |
... and would you expect an auto scaling margin around the line? If so, we should remove the funky logic and just autoscale. |
I would expect a margin, for the same reason we have margins at all. Removing funky logic sounds good 😄. |
@dopplershift If you plot a vertical line at x=0.99 while the current limits (computed on the rest of the data) is (0, 1), do you expect the 5% margin to go to 1.05(-epsilon)? |
The reason why I was confused is that https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.axvline.html |
Yeah, thats an unfortunate artifact of just repeating the |
@anntzer Personally, I expect the margin to increase as well. It may "just" be a notational line, but the whole point of margins is better aesthetics around things on the plot, keeping all items (dataspace wise) from being right on the edge. |
so in #14651 (comment) you think we should increase the margins in the lower left plot? |
Yes. |
Do we understand why the complicated logic was put in, and does removing it fail any tests? |
I feel strongly that the behaviour should be simple and consistent. I feel mildly that these should not participate in auto scaling, but don’t mind the opposite behaviour |
I agree about simple and consistent. I can say that my reaction, if I call |
pathces.Rectangle has the non-auto-scaling behavior, which is problematic if some things remain where they are and others are scaled. I agree the behavior should be consistent. |
Bug report
Bug summary
Autoscaling behavior around axvlines is inconsistent.
Code for reproduction
Actual outcome
Top row: when the axvline is drawn in (0, 1) (the default), the margins are left as is; when the axvline is drawn outside of it, the margins move to surround it.
Bottom row: when the axvline is drawn within the margins imposed by the "other" line plot, the margins are left as is; when the axvline is drawn outside of it, yet another 5% margins are applied to it.
Expected outcome
Consistent behavior between left and right.
I think it's mostly just a matter of
(and likewise for axhline); OTOH I guess some may possibly actually be relying on non-expansion of margins when drawing axvlines just outside of the data limits but still within the margins? dunno.
Matplotlib version
print(matplotlib.get_backend())
): qt5aggThe text was updated successfully, but these errors were encountered: