@@ -671,6 +671,47 @@ def test_legend_labelcolor_linecolor():
671
671
assert mpl .colors .same_color (text .get_color (),color )
672
672
673
673
674
+ def test_legend_pathcollection_labelcolor_linecolor ():
675
+ # test the labelcolor for labelcolor='linecolor' on PathCollection
676
+ fig ,ax = plt .subplots ()
677
+ ax .scatter (np .arange (10 ),np .arange (10 )* 1 ,label = '#1' ,c = 'r' )
678
+ ax .scatter (np .arange (10 ),np .arange (10 )* 2 ,label = '#2' ,c = 'g' )
679
+ ax .scatter (np .arange (10 ),np .arange (10 )* 3 ,label = '#3' ,c = 'b' )
680
+
681
+ leg = ax .legend (labelcolor = 'linecolor' )
682
+ for text ,color in zip (leg .get_texts (), ['r' ,'g' ,'b' ]):
683
+ assert mpl .colors .same_color (text .get_color (),color )
684
+
685
+
686
+ def test_legend_pathcollection_labelcolor_linecolor_iterable ():
687
+ # test the labelcolor for labelcolor='linecolor' on PathCollection
688
+ # with iterable colors
689
+ fig ,ax = plt .subplots ()
690
+ colors = np .random .default_rng ().choice (['r' ,'g' ,'b' ],10 )
691
+ ax .scatter (np .arange (10 ),np .arange (10 )* 1 ,label = '#1' ,c = colors )
692
+
693
+ leg = ax .legend (labelcolor = 'linecolor' )
694
+ for text ,color in zip (leg .get_texts (), ['k' ]):
695
+ assert mpl .colors .same_color (text .get_color (),color )
696
+
697
+
698
+ def test_legend_pathcollection_labelcolor_linecolor_cmap ():
699
+ # test the labelcolor for labelcolor='linecolor' on PathCollection
700
+ # with a colormap
701
+ fig ,ax = plt .subplots ()
702
+ ax .scatter (
703
+ np .arange (10 ),
704
+ np .arange (10 ),
705
+ label = '#1' ,
706
+ c = np .arange (10 ),
707
+ cmap = "Reds"
708
+ )
709
+
710
+ leg = ax .legend (labelcolor = 'linecolor' )
711
+ for text ,color in zip (leg .get_texts (), ['k' ]):
712
+ assert mpl .colors .same_color (text .get_color (),color )
713
+
714
+
674
715
def test_legend_labelcolor_markeredgecolor ():
675
716
# test the labelcolor for labelcolor='markeredgecolor'
676
717
fig ,ax = plt .subplots ()
@@ -683,6 +724,49 @@ def test_legend_labelcolor_markeredgecolor():
683
724
assert mpl .colors .same_color (text .get_color (),color )
684
725
685
726
727
+ def test_legend_pathcollection_labelcolor_markeredgecolor ():
728
+ # test the labelcolor for labelcolor='markeredgecolor' on PathCollection
729
+ fig ,ax = plt .subplots ()
730
+ ax .scatter (np .arange (10 ),np .arange (10 )* 1 ,label = '#1' ,edgecolor = 'r' )
731
+ ax .scatter (np .arange (10 ),np .arange (10 )* 2 ,label = '#2' ,edgecolor = 'g' )
732
+ ax .scatter (np .arange (10 ),np .arange (10 )* 3 ,label = '#3' ,edgecolor = 'b' )
733
+
734
+ leg = ax .legend (labelcolor = 'markeredgecolor' )
735
+ for text ,color in zip (leg .get_texts (), ['r' ,'g' ,'b' ]):
736
+ assert mpl .colors .same_color (text .get_color (),color )
737
+
738
+
739
+ def test_legend_pathcollection_labelcolor_markeredgecolor_iterable ():
740
+ # test the labelcolor for labelcolor='markeredgecolor' on PathCollection
741
+ # with iterable colors
742
+ fig ,ax = plt .subplots ()
743
+ colors = np .random .default_rng ().choice (['r' ,'g' ,'b' ],10 )
744
+ ax .scatter (np .arange (10 ),np .arange (10 )* 1 ,label = '#1' ,edgecolor = colors )
745
+
746
+ leg = ax .legend (labelcolor = 'markeredgecolor' )
747
+ for text ,color in zip (leg .get_texts (), ['k' ]):
748
+ assert mpl .colors .same_color (text .get_color (),color )
749
+
750
+
751
+ def test_legend_pathcollection_labelcolor_markeredgecolor_cmap ():
752
+ # test the labelcolor for labelcolor='markeredgecolor' on PathCollection
753
+ # with a colormap
754
+ fig ,ax = plt .subplots ()
755
+ edgecolors = mpl .cm .viridis (np .random .rand (10 ))
756
+ ax .scatter (
757
+ np .arange (10 ),
758
+ np .arange (10 ),
759
+ label = '#1' ,
760
+ c = np .arange (10 ),
761
+ edgecolor = edgecolors ,
762
+ cmap = "Reds"
763
+ )
764
+
765
+ leg = ax .legend (labelcolor = 'markeredgecolor' )
766
+ for text ,color in zip (leg .get_texts (), ['k' ]):
767
+ assert mpl .colors .same_color (text .get_color (),color )
768
+
769
+
686
770
def test_legend_labelcolor_markerfacecolor ():
687
771
# test the labelcolor for labelcolor='markerfacecolor'
688
772
fig ,ax = plt .subplots ()
@@ -695,6 +779,48 @@ def test_legend_labelcolor_markerfacecolor():
695
779
assert mpl .colors .same_color (text .get_color (),color )
696
780
697
781
782
+ def test_legend_pathcollection_labelcolor_markerfacecolor ():
783
+ # test the labelcolor for labelcolor='markerfacecolor' on PathCollection
784
+ fig ,ax = plt .subplots ()
785
+ ax .scatter (np .arange (10 ),np .arange (10 )* 1 ,label = '#1' ,facecolor = 'r' )
786
+ ax .scatter (np .arange (10 ),np .arange (10 )* 2 ,label = '#2' ,facecolor = 'g' )
787
+ ax .scatter (np .arange (10 ),np .arange (10 )* 3 ,label = '#3' ,facecolor = 'b' )
788
+
789
+ leg = ax .legend (labelcolor = 'markerfacecolor' )
790
+ for text ,color in zip (leg .get_texts (), ['r' ,'g' ,'b' ]):
791
+ assert mpl .colors .same_color (text .get_color (),color )
792
+
793
+
794
+ def test_legend_pathcollection_labelcolor_markerfacecolor_iterable ():
795
+ # test the labelcolor for labelcolor='markerfacecolor' on PathCollection
796
+ # with iterable colors
797
+ fig ,ax = plt .subplots ()
798
+ colors = np .random .default_rng ().choice (['r' ,'g' ,'b' ],10 )
799
+ ax .scatter (np .arange (10 ),np .arange (10 )* 1 ,label = '#1' ,facecolor = colors )
800
+
801
+ leg = ax .legend (labelcolor = 'markerfacecolor' )
802
+ for text ,color in zip (leg .get_texts (), ['k' ]):
803
+ assert mpl .colors .same_color (text .get_color (),color )
804
+
805
+
806
+ def test_legend_pathcollection_labelcolor_markfacecolor_cmap ():
807
+ # test the labelcolor for labelcolor='markerfacecolor' on PathCollection
808
+ # with colormaps
809
+ fig ,ax = plt .subplots ()
810
+ facecolors = mpl .cm .viridis (np .random .rand (10 ))
811
+ ax .scatter (
812
+ np .arange (10 ),
813
+ np .arange (10 ),
814
+ label = '#1' ,
815
+ c = np .arange (10 ),
816
+ facecolor = facecolors
817
+ )
818
+
819
+ leg = ax .legend (labelcolor = 'markerfacecolor' )
820
+ for text ,color in zip (leg .get_texts (), ['k' ]):
821
+ assert mpl .colors .same_color (text .get_color (),color )
822
+
823
+
698
824
@pytest .mark .parametrize ('color' , ('red' ,'none' , (.5 ,.5 ,.5 )))
699
825
def test_legend_labelcolor_rcparam_single (color ):
700
826
# test the rcParams legend.labelcolor for a single color