Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70dd56d

Browse files
author
Julien Lecoeur
committed
Add legend handler for Text artists
1 parent d7bd069 commit 70dd56d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/matplotlib/legend_handler.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,3 +690,26 @@ def create_artists(self, legend, orig_handle,
690690
self.update_prop(p, orig_handle, legend)
691691
p.set_transform(trans)
692692
return [p]
693+
694+
695+
class HandlerText(HandlerBase):
696+
"""
697+
Handler for Text instances.
698+
"""
699+
def create_artists(self, legend, orig_handle,
700+
xdescent, ydescent, width, height, fontsize, trans):
701+
t = Text(x=-xdescent + width / 3,
702+
y=-ydescent + height / 4,
703+
text="a")
704+
705+
# Use original text if it is short
706+
text = orig_handle.get_text()
707+
if len(text) < 2:
708+
t.set_text(text)
709+
710+
# Copy text attributes, except fontsize
711+
self.update_prop(t, orig_handle, legend)
712+
t.set_transform(trans)
713+
t.set_fontsize(2 * fontsize / 3)
714+
715+
return [t]

0 commit comments

Comments
 (0)