8000 Annotation legend by jlecoeur · Pull Request #8292 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Annotation legend #8292

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

Closed
wants to merge 13 commits into from
Closed
Prev Previous commit
Next Next commit
Add legend handler for Text artists
  • Loading branch information
Julien Lecoeur committed Mar 14, 2017
commit 70dd56d49c1e21783aea8a06c1a5f34f842aafdb
23 changes: 23 additions & 0 deletions lib/matplotlib/legend_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,3 +690,26 @@ def create_artists(self, legend, orig_handle,
self.update_prop(p, orig_handle, legend)
p.set_transform(trans)
return [p]


class HandlerText(HandlerBase):
"""
Handler for Text instances.
"""
def create_artists(self, legend, orig_handle,
xdescent, ydescent, width, height, fontsize, trans):
t = Text(x=-xdescent + width / 3,
y=-ydescent + height / 4,
text="a")

# Use original text if it is short
text = orig_handle.get_text()
if len(text) < 2:
t.set_text(text)

# Copy text attributes, except fontsize
self.update_prop(t, orig_handle, legend)
t.set_transform(trans)
t.set_fontsize(2 * fontsize / 3)

return [t]
0