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