-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
tight_layout for plot with non-clipped screen-unit items causes issues on zoom #12256
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
For a figure with multiple items, clicking the zoom button causes irregular change in layout. Attached is a code to demo issue in PYQT4. This is only present in new V3 of matplotlib.
Here are images of original plot and response to zoom behavior: |
Yes that’s because the annotation is still in its old spot so the axes is made small enough to still show the annotation. If you’d like to exclude the annotation from the layout then you can set its inlayout property to False (on a phone so cant look up exact syntax, but it’s as in the API note) |
So the work around is to exclude the annotation from the layout: ann = self.plot1.annotate(annotxt, fontsize=13, xy=(1.25, 2),
xytext=(1.5, 1.75),
arrowprops=dict(facecolor='black', shrink=0.15),
)
ann.set_in_layout(False) I'd have thought that setting Sorry this behaviour has changed; But then we also get bug reports the other way, that someone's annotation is off the page after tight layout has been called. I think we are open to arguments that some artists should default to something other than One other todo here: I changed constrained layout to simply not adjust the layout when these sorts of collapses happen. Its easy to change tight_layout to do the same. |
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0.0, 2.0, 0.01)
s1 = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots(tight_layout=True)
ax.plot(t, s1, c='r', lw='2', zorder=1, label='Sin')
ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='About as simple as it gets, folks')
ax.scatter(1.25, 2.0, c='b', zorder=2, lw=2.0)
annotxt = 'max. voltage: {0:0.2g} mV'.format(2.0)
ann = ax.annotate(annotxt, fontsize=13, xy=(1.25, 2),
xytext=(1.5, 1.75),
arrowprops=dict(facecolor='black', shrink=0.15),
annotation_clip=True)
ann.set_in_layout(True)
plt.show() |
Ok, so issue is understood (thanks). |
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0.0, 2.0, 0.01)
s1 = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots(tight_layout=True)
ax.plot(t, s1, c='r', lw='2', zorder=1, label='Sin')
ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='About as simple as it gets, folks')
ax.scatter(1.25, 2.0, c='b', zorder=2, lw=2.0)
annotxt = 'max. voltage: {0:0.2g} mV'.format(2.0)
ann = ax.annotate(annotxt, fontsize=13, xy=(1.25, 2),
xytext=(1.5, 1.75),
arrowprops=dict(facecolor='black', shrink=0.15),
clip_on=True)
plt.show() also works fine, though its clipped in the first rendering because its outside of the axes. The annotation is part of the axes. I think it makes sense to make room for it as part of the axes if its been attached to the axes. I think there is an argument for making a |
Discussed on weekly call a couple of weeks ago and we are still going to include axes artists in the layout by default. So I’ll close as won’t fix. Sorry though that this broke something for you. |
Originally posted by @jklymak in #12239 (comment)
The text was updated successfully, but these errors were encountered: