Skip to content

FIX: return proper legend window extent #10910

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

Merged
merged 2 commits into from
Apr 8, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Mar 28, 2018

PR Summary

As per #10844, it was not possible to properly use text.OffsetFrom if the artist was a legend. The issue was that legend.get_window_extent was calling the wrong patch object to get the patch location.

The following code now returns properly placed text regardless of the savefig dpi:

import matplotlib.pyplot as plt
import matplotlib.text

fig, ax = plt.subplots(dpi=200, figsize=(3,3))
ax.plot(range(10), label='Bah')
ax.set_xticks([])
ax.set_yticks([])
legend = ax.legend(loc="upper right")

offset = matplotlib.text.OffsetFrom(legend, (1.0, 0.0))
ax.annotate("info_string", xy=(0,0),size=14,
            xycoords='figure fraction', xytext=(0, 0), textcoords=offset,
            horizontalalignment='right', verticalalignment='top')
fig.savefig('plot1.png', dpi=100)

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant

@jklymak jklymak added this to the v3.0 milestone Mar 28, 2018
@jklymak jklymak force-pushed the fix-proper-legend-window-extent branch from 3b27337 to 9a03a2d Compare March 28, 2018 20:36
@jklymak
Copy link
Member Author

jklymak commented Apr 1, 2018

Bump - this is a pretty straightforward one that fixes at least one reported issue

@phobson phobson merged commit 9b15a52 into matplotlib:master Apr 8, 2018
@jklymak
Copy link
Member Author

jklymak commented Apr 8, 2018

Thanks @phobson

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

Successfully merging this pull request may close these issues.

4 participants