-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Add Axes method for drawing infinite lines #9321
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
Conversation
Can you document how this interacts with semilog and loglog plots? (Even if it is "it doesn't work with them".)
a8d7e7a
to
651ee83
Compare
Hmm, I can't reproduce the test failure
You can download the results from AppVeyor:
axline-failed-diff
Wrong version of FreeType used for test?
syrte
commented
Jan 19, 2018
@anntzer I've tried this code, it seems not support any type of log scale yet.
651ee83
to
49da75e
Compare
🎉 it works!
029e272
to
0c0d30b
Compare
what happens if we make it non-linear scale after calling axline
?
Then you end up with a line that's incorrect in the same way as if it were set beforehand.
Can we refactor axhline and axvline as special cases of this function?
I also think we (削除) should add a what's new entry, and (削除ここまで) update the following example with this new function: https://matplotlib.org/devdocs/gallery/subplots_axes_and_figures/axhspan_demo.html#sphx-glr-gallery-subplots-axes-and-figures-axhspan-demo-py
thanks!
Reading axhline's and axvline's code, I see that it's not trivial (I do have to say that it's a bit annoying to have such closely related functions with slightly different APIs)
0c0d30b
to
737ee9f
Compare
Okay I've done a big 'ol rebase and squash, and this now uses xy1
and xy2
.
737ee9f
to
8c211c9
Compare
Clean up axline Add axline image test Fix test image Add what's new Add note about log axes Error if trying to draw line on non-linear axes Fix scale checking Fix docstring interpolation Chnage to using xy1, xy2 Fix docs and closeness checking Raise error if points are the same Swap axline test to image comparison
ee7707b
to
7c28bcd
Compare
I think that's all the comments taken care of, so feel free to review again. I've squashed everything into one commit, so there's no extra test image files hanging around any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add axline to the section „Span" in axes_api.rst.
I just noticed another point: Currently, axline() does not trigger an update of the autolimits in use (for example a call to axline() when the view limits are x=0..1, y=0..1 leaves them unchanged); however, adding more plots after a call to axline() shows that the internal data limits have been changed by axline to include x=0..1, y=(whatever y range corresponds to x=0..1 in the axline). For example, after plt.gca().axline((3, 7), (5, 6)); plt.plot([0, 1])
, one gets
test
I think reasonable approaches would be to use the two points passed to axline() as "autoscaling limits", or to just not update the autoscale limits at all (the relevant code appears to be in Axes._update_line_limits, which is called by Axes.add_line).
I agree that not setting auto-limits is a good idea, but after a bit of a play around I'm not sure what the right way to do that is. Is there an easy way to exclude an Artist
from autoscale calculations?
This was discussed a while ago and there isn't really a smart way to do it; what I personally do is
@contextmanager
def ignore_in_autoscale(ax):
"""
When autoscaling, ignore the extents of artists created in the context.
"""
dl = ax.dataLim.frozen()
try:
yield
finally:
ax.dataLim = dl
ax.autoscale_view(scalex=ax.get_autoscalex_on(),
scaley=ax.get_autoscaley_on())
(basically, save the datalimits first, add the artist, then restore the datalimits), which is a bit of a hack.
Uh oh!
There was an error while loading. Please reload this page.
Supersedes #7506 - cleans up docstring and adds a test. Fixes #5253.