Skip to content

FIX: return proper legend window extent - #10910

Merged
phobson merged 2 commits into
matplotlib:masterfrom
jklymak:fix-proper-legend-window-extent
Apr 8, 2018
Merged

phobson merged 2 commits into
matplotlib:masterfrom
jklymak:fix-proper-legend-window-extent

Conversation

@jklymak

@jklymak jklymak commented Mar 28, 2018

Copy link
Copy Markdown
Member

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

jklymak commented Apr 1, 2018

Copy link
Copy Markdown
Member Author

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

jklymak commented Apr 8, 2018

Copy link
Copy Markdown
Member Author

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