-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Annotations are not clipped properly #14354
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
Notice that if one does not set xlim and ylim, the same happens, where autoscaling would be an expected outcome, as is part of issue #10497. |
If the
the output is as expected. A confusing bit is that the annotations have a |
So this is purely an issue of setting defaults? I would then suggest to go from |
@ImportanceOfBeingErnest There is a catch: Why does this not occur when using import matplotlib.pyplot as plt
plt.xlim(0,1)
plt.ylim(0,1)
plt.annotate(xy=(3, 3), s='test')
plt.savefig("test.png") |
No, it's not an issue of the correct defaults. The issue is that The issue only occurs if you use In principle the defaults are fine: So possible solutions are:
|
As of my understanding while quickly looking through the source, lib/matplotlib/artist.py uses |
Due to the drawbacks of both possible solutions to this, I don't think this will be solved anytime soon. Also, one may consider it as a documentation issue, clarifying the role of Hence, relabeling and remilestoning. |
Sorry for reacting so late to this, but in original example, the annotation is NOT shown outside the axes, although I do not change the defaults. |
Yes, but you can easily get the annotation to show up using
So the question is, whether it's worth putting in a hacky solution with some heuristics about whether or not to show the annotation in case |
So, by default its none, and its not drawn. But because its not clipped using the usual clipping argument, its still included in the tight_layout calculation. I'm not sure I understand the subtleties of why annotations have multiple clip arguments, or what behaviour is particularly desired here. |
@ImportanceOfBeingErnest I'm not quite sure I get this. When the default for |
Thank you for the explanation and the work of doing a GIF! |
OK, but I don't think we ever want the |
I'm not sure. Maybe in cases where you don't have any arrow? What's the alternative, though? Giving |
Hi, just to give a feedback (I hope this is the appropriate place) I agree with @jklymak: the case |
I do not know what changed but I just tried this with Matplotlib v3.8.4 in a notebook and got the expected result, i.e. the figure is not resized to include the invisible annotation. import matplotlib.pyplot as plt
plt.xlim(0,1)
plt.ylim(0,1)
plt.annotate('test', xy=(3, 3)) |
This was fixed by #18772. |
Bug report
Bug summary
Drawing an annotation outside the visible region inline in jupyter notebook leads to whitespace added around the figure extending it to where the annotation would be.
Code for reproduction
Actual outcome
Expected outcome
Matplotlib version
print(matplotlib.get_backend())
):module://ipykernel.pylab.backend_inline
Everything is installed via pip, pip and python are installed via apt.
The text was updated successfully, but these errors were encountered: