Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5e1b5fe

Browse files
committed
Added test
1 parente4ee185 commit5e1b5fe

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

‎examples/text_labels_and_annotations/legend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
ax.plot(a,d,'k:',label='Data length')
2222
ax.plot(a,c+d,'k',label='Total message length')
2323

24-
#Create an arrow with pre-defined label.
24+
#Create an arrow with pre-defined label.
2525
ax.annotate("",xy=(1.5,4.5),xytext=(1.5,9.0),
26-
arrowprops={'arrowstyle':'<->','color':'C7'},label='Distance')
26+
arrowprops={'arrowstyle':'<->','color':'C7'},label='Distance')
2727

2828
legend=ax.legend(loc='upper center',shadow=True,fontsize='large')
2929

‎lib/matplotlib/legend_handler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,8 @@ class HandlerFancyArrowPatch(HandlerPatch):
812812
"""
813813
Handler for `~.FancyArrowPatch` instances.
814814
"""
815-
def_create_patch(self,legend,orig_handle,xdescent,ydescent,width,height,fontsize):
815+
def_create_patch(self,legend,orig_handle,xdescent,ydescent,width,
816+
height,fontsize):
816817
arrow=FancyArrowPatch([-xdescent,
817818
-ydescent+height/2],
818819
[-xdescent+width,
@@ -849,9 +850,7 @@ def create_artists(self, legend, orig_handle, xdescent, ydescent, width,
849850
height,fontsize,trans):
850851

851852
iforig_handle.arrow_patchisnotNone:
852-
853853
# Arrow without text
854-
855854
handler=HandlerFancyArrowPatch()
856855
handle=orig_handle.arrow_patch
857856

‎lib/matplotlib/tests/test_legend.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,3 +927,22 @@ def test_legend_markers_from_line2d():
927927

928928
assertmarkers==new_markers==_markers
929929
assertlabels==new_labels
930+
931+
932+
deftest_annotation_legend():
933+
fig,ax=plt.subplots()
934+
ax.annotate("",xy=(0.5,0.5),xytext=(0.5,0.7),
935+
arrowprops={'arrowstyle':'<->'},label="Bar")
936+
legend=ax.legend()
937+
assertlen(legend.get_texts())==1
938+
ax.annotate("Foo",xy=(0.3,0.3))
939+
legend=ax.legend()
940+
assertlen(legend.get_texts())==1
941+
ax.annotate("FooBar",xy=(0.7,0.7),xytext=(0.7,0.9),
942+
arrowprops={'arrowstyle':'->'})
943+
legend=ax.legend()
944+
assertlen(legend.get_texts())==1
945+
ax.annotate("Foo",xy=(0.1,0.1),xytext=(0.1,0.7),
946+
arrowprops={'arrowstyle':'<-'},label="Foo")
947+
legend=ax.legend()
948+
assertlen(legend.get_texts())==2

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp