@@ -671,6 +671,41 @@ def test_legend_labelcolor_linecolor():
671671 assert mpl .colors .same_color (text .get_color (), color )
672672
673673
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+ text , = leg .get_texts ()
695+ assert mpl .colors .same_color (text .get_color (), 'black' )
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 (np .arange (10 ), np .arange (10 ), c = np .arange (10 ), label = '#1' )
703+
704+ leg = ax .legend (labelcolor = 'linecolor' )
705+ text , = leg .get_texts ()
706+ assert mpl .colors .same_color (text .get_color (), 'black' )
707+
708+
674709def test_legend_labelcolor_markeredgecolor ():
675710 # test the labelcolor for labelcolor='markeredgecolor'
676711 fig , ax = plt .subplots ()
@@ -683,6 +718,49 @@ def test_legend_labelcolor_markeredgecolor():
683718 assert mpl .colors .same_color (text .get_color (), color )
684719
685720
721+ def test_legend_pathcollection_labelcolor_markeredgecolor ():
722+ # test the labelcolor for labelcolor='markeredgecolor' on PathCollection
723+ fig , ax = plt .subplots ()
724+ ax .scatter (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , edgecolor = 'r' )
725+ ax .scatter (np .arange (10 ), np .arange (10 )* 2 , label = '#2' , edgecolor = 'g' )
726+ ax .scatter (np .arange (10 ), np .arange (10 )* 3 , label = '#3' , edgecolor = 'b' )
727+
728+ leg = ax .legend (labelcolor = 'markeredgecolor' )
729+ for text , color in zip (leg .get_texts (), ['r' , 'g' , 'b' ]):
730+ assert mpl .colors .same_color (text .get_color (), color )
731+
732+
733+ def test_legend_pathcollection_labelcolor_markeredgecolor_iterable ():
734+ # test the labelcolor for labelcolor='markeredgecolor' on PathCollection
735+ # with iterable colors
736+ fig , ax = plt .subplots ()
737+ colors = np .random .default_rng ().choice (['r' , 'g' , 'b' ], 10 )
738+ ax .scatter (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , edgecolor = colors )
739+
740+ leg = ax .legend (labelcolor = 'markeredgecolor' )
741+ for text , color in zip (leg .get_texts (), ['k' ]):
742+ assert mpl .colors .same_color (text .get_color (), color )
743+
744+
745+ def test_legend_pathcollection_labelcolor_markeredgecolor_cmap ():
746+ # test the labelcolor for labelcolor='markeredgecolor' on PathCollection
747+ # with a colormap
748+ fig , ax = plt .subplots ()
749+ edgecolors = mpl .cm .viridis (np .random .rand (10 ))
750+ ax .scatter (
751+ np .arange (10 ),
752+ np .arange (10 ),
753+ label = '#1' ,
754+ c = np .arange (10 ),
755+ edgecolor = edgecolors ,
756+ cmap = "Reds"
757+ )
758+
759+ leg = ax .legend (labelcolor = 'markeredgecolor' )
760+ for text , color in zip (leg .get_texts (), ['k' ]):
761+ assert mpl .colors .same_color (text .get_color (), color )
762+
763+
686764def test_legend_labelcolor_markerfacecolor ():
687765 # test the labelcolor for labelcolor='markerfacecolor'
688766 fig , ax = plt .subplots ()
@@ -695,6 +773,48 @@ def test_legend_labelcolor_markerfacecolor():
695773 assert mpl .colors .same_color (text .get_color (), color )
696774
697775
776+ def test_legend_pathcollection_labelcolor_markerfacecolor ():
777+ # test the labelcolor for labelcolor='markerfacecolor' on PathCollection
778+ fig , ax = plt .subplots ()
779+ ax .scatter (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , facecolor = 'r' )
780+ ax .scatter (np .arange (10 ), np .arange (10 )* 2 , label = '#2' , facecolor = 'g' )
781+ ax .scatter (np .arange (10 ), np .arange (10 )* 3 , label = '#3' , facecolor = 'b' )
782+
783+ leg = ax .legend (labelcolor = 'markerfacecolor' )
784+ for text , color in zip (leg .get_texts (), ['r' , 'g' , 'b' ]):
785+ assert mpl .colors .same_color (text .get_color (), color )
786+
787+
788+ def test_legend_pathcollection_labelcolor_markerfacecolor_iterable ():
789+ # test the labelcolor for labelcolor='markerfacecolor' on PathCollection
790+ # with iterable colors
791+ fig , ax = plt .subplots ()
792+ colors = np .random .default_rng ().choice (['r' , 'g' , 'b' ], 10 )
793+ ax .scatter (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , facecolor = colors )
794+
795+ leg = ax .legend (labelcolor = 'markerfacecolor' )
796+ for text , color in zip (leg .get_texts (), ['k' ]):
797+ assert mpl .colors .same_color (text .get_color (), color )
798+
799+
800+ def test_legend_pathcollection_labelcolor_markfacecolor_cmap ():
801+ # test the labelcolor for labelcolor='markerfacecolor' on PathCollection
802+ # with colormaps
803+ fig , ax = plt .subplots ()
804+ facecolors = mpl .cm .viridis (np .random .rand (10 ))
805+ ax .scatter (
806+ np .arange (10 ),
807+ np .arange (10 ),
808+ label = '#1' ,
809+ c = np .arange (10 ),
810+ facecolor = facecolors
811+ )
812+
813+ leg = ax .legend (labelcolor = 'markerfacecolor' )
814+ for text , color in zip (leg .get_texts (), ['k' ]):
815+ assert mpl .colors .same_color (text .get_color (), color )
816+
817+
698818@pytest .mark .parametrize ('color' , ('red' , 'none' , (.5 , .5 , .5 )))
699819def test_legend_labelcolor_rcparam_single (color ):
700820 # test the rcParams legend.labelcolor for a single color
0 commit comments