Skip to content
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

Matplotlib 1.5.1 ignores annotation_clip parameter #6151

Closed
mikoff opened this issue Mar 13, 2016 · 5 comments
Closed

Matplotlib 1.5.1 ignores annotation_clip parameter #6151

mikoff opened this issue Mar 13, 2016 · 5 comments

Comments

@mikoff
Copy link

mikoff commented Mar 13, 2016

Hello!
I think there is a problem with matplotlib annotation_clip value while using it to place a comment outside the main plot area. Surprisingly, but it works in jupyter notebook.

Matplotlib version: 1.5.1
Platform: Linux
Backend: Qt, TkAgg
Installed using: pip
To help us understand and resolve your issue please check that you have provided
the information below.

Minimal working example:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
x = np.arange(0,1,0.001)
y = 0.5*np.sin(x) + np.cos(x)**2
ax.plot(x,y)

ax.annotate('Test annotation', xy=(1.5, 1.5), xycoords='data', annotation_clip=False)
plt.show()

@tacaswell
Copy link
Member

by 'in a jupyter notebook' you mean with the inline backend? The inline backend saves with bounding_box_inches=='tight' which was meant to 'shrink' the bounding box to exclude extra whitespace (at the cost of losing strict control of the figure size) but also will expand the saved area to include artists not strictly in the visible section of the figure.

Adding

ax.set_xlim([0, 1.4])
ax.set_ylim([0, 1.4])

you will see the start of your text.

I suspect you should be using

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
x = np.arange(0, 1, 0.001)
y = (0.5 * np.sin(x)) + (np.cos(x) ** 2)
ax.plot(x, y)
ax.annotate('Test annotation', xy=(1, 1),
            xycoords='axes fraction',
            xytext=(0, 12),
            textcoords='offset points',
            ha='right',
            annotation_clip=False)
plt.show()

instead.

so

@mikoff
Copy link
Author

mikoff commented Mar 13, 2016

Thank you!
I suppose that I misunderstood the documentation. I thought that the figure will be expanded automatically with annotation_clip parameter set to False.

@tacaswell
Copy link
Member

If the documentation confused you, can you suggest a way to clarify it?

Not auto 'shrink wrapping' is frequently a feature, for example when making animations (where every frame must be exactly the same pixel count) or for embedding in other documents where matching font size is important.

@mikoff
Copy link
Author

mikoff commented Mar 13, 2016

I was guided by this api section.

To my sense, something like:

Note: the figure won`t be extended to draw the text if its position exceeds figure dimensions.

after:

The annotation_clip attribute controls the visibility of the annotation when it goes outside the axes area. If True, the annotation will only be drawn when the xy is inside the axes. If False, the annotation will always be drawn regardless of its position. The default is None, which behave as True only if xycoords is “data”.

will be more than enough.

I played a bit and understood the mechanics behind this option - it draws the text, but the text is only shown when its position is within current figure dimensions. Thanks again!

@WeatherGod
Copy link
Member

I think that statement (modulo an addendum about bbox_inches='tight') would
be fair enough. The focus of the original statement was to provide a means
for placing annotations outside an axes area, but it was probably assumed
that it would still be inside the figure.

Would you like to put together a PR updating that documentation?

On Sun, Mar 13, 2016 at 5:25 PM, mikoff notifications@github.com wrote:

I was guided by this documentation [section].(
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.text)

To my sense, something like:

Note: the figure won`t be extended to draw the text if its position
exceeds figure dimensions.

after:

The annotation_clip attribute controls the visibility of the annotation
when it goes outside the axes area. If True, the annotation will only be
drawn when the xy is inside the axes. If False, the annotation will always
be drawn regardless of its position. The default is None, which behave as
True only if xycoords is “data”.

will be more than enough.

I played a bit and understood the mechanics behind this option - it draws
the text, but the text is only shown when its position is within current
figure dimensions.


Reply to this email directly or view it on GitHub
#6151 (comment)
.

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

No branches or pull requests

3 participants