@@ -644,6 +644,85 @@ def test_legend_labelcolor_markerfacecolor():
644644 assert mpl .colors .same_color (text .get_color (), color )
645645
646646
647+ @pytest .mark .parametrize ('color' , ('red' , 'none' , (.5 , .5 , .5 )))
648+ def test_legend_labelcolor_rcparam_single (color ):
649+ # test the rcParams legend.labelcolor for a single color
650+ fig , ax = plt .subplots ()
651+ ax .plot (np .arange (10 ), np .arange (10 )* 1 , label = '#1' )
652+ ax .plot (np .arange (10 ), np .arange (10 )* 2 , label = '#2' )
653+ ax .plot (np .arange (10 ), np .arange (10 )* 3 , label = '#3' )
654+
655+ mpl .rcParams ['legend.labelcolor' ] = color
656+ leg = ax .legend ()
657+ for text in leg .get_texts ():
658+ assert mpl .colors .same_color (text .get_color (), color )
659+
660+
661+ def test_legend_labelcolor_rcparam_linecolor ():
662+ # test the rcParams legend.labelcolor for a linecolor
663+ fig , ax = plt .subplots ()
664+ ax .plot (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , color = 'r' )
665+ ax .plot (np .arange (10 ), np .arange (10 )* 2 , label = '#2' , color = 'g' )
666+ ax .plot (np .arange (10 ), np .arange (10 )* 3 , label = '#3' , color = 'b' )
667+
668+ mpl .rcParams ['legend.labelcolor' ] = 'linecolor'
669+ leg = ax .legend ()
670+ for text , color in zip (leg .get_texts (), ['r' , 'g' , 'b' ]):
671+ assert mpl .colors .same_color (text .get_color (), color )
672+
673+
674+ def test_legend_labelcolor_rcparam_markeredgecolor ():
675+ # test the labelcolor for labelcolor='markeredgecolor'
676+ fig , ax = plt .subplots ()
677+ ax .plot (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , markeredgecolor = 'r' )
678+ ax .plot (np .arange (10 ), np .arange (10 )* 2 , label = '#2' , markeredgecolor = 'g' )
679+ ax .plot (np .arange (10 ), np .arange (10 )* 3 , label = '#3' , markeredgecolor = 'b' )
680+
681+ mpl .rcParams ['legend.labelcolor' ] = 'markeredgecolor'
682+ leg = ax .legend ()
683+ for text , color in zip (leg .get_texts (), ['r' , 'g' , 'b' ]):
684+ assert mpl .colors .same_color (text .get_color (), color )
685+
686+
687+ def test_legend_labelcolor_rcparam_markeredgecolor_short ():
688+ # test the labelcolor for labelcolor='markeredgecolor'
689+ fig , ax = plt .subplots ()
690+ ax .plot (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , markeredgecolor = 'r' )
691+ ax .plot (np .arange (10 ), np .arange (10 )* 2 , label = '#2' , markeredgecolor = 'g' )
692+ ax .plot (np .arange (10 ), np .arange (10 )* 3 , label = '#3' , markeredgecolor = 'b' )
693+
694+ mpl .rcParams ['legend.labelcolor' ] = 'mec'
695+ leg = ax .legend ()
696+ for text , color in zip (leg .get_texts (), ['r' , 'g' , 'b' ]):
697+ assert mpl .colors .same_color (text .get_color (), color )
698+
699+
700+ def test_legend_labelcolor_rcparam_markerfacecolor ():
701+ # test the labelcolor for labelcolor='markeredgecolor'
702+ fig , ax = plt .subplots ()
703+ ax .plot (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , markerfacecolor = 'r' )
704+ ax .plot (np .arange (10 ), np .arange (10 )* 2 , label = '#2' , markerfacecolor = 'g' )
705+ ax .plot (np .arange (10 ), np .arange (10 )* 3 , label = '#3' , markerfacecolor = 'b' )
706+
707+ mpl .rcParams ['legend.labelcolor' ] = 'markerfacecolor'
708+ leg = ax .legend ()
709+ for text , color in zip (leg .get_texts (), ['r' , 'g' , 'b' ]):
710+ assert mpl .colors .same_color (text .get_color (), color )
711+
712+
713+ def test_legend_labelcolor_rcparam_markerfacecolor_short ():
714+ # test the labelcolor for labelcolor='markeredgecolor'
715+ fig , ax = plt .subplots ()
716+ ax .plot (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , markerfacecolor = 'r' )
717+ ax .plot (np .arange (10 ), np .arange (10 )* 2 , label = '#2' , markerfacecolor = 'g' )
718+ ax .plot (np .arange (10 ), np .arange (10 )* 3 , label = '#3' , markerfacecolor = 'b' )
719+
720+ mpl .rcParams ['legend.labelcolor' ] = 'mfc'
721+ leg = ax .legend ()
722+ for text , color in zip (leg .get_texts (), ['r' , 'g' , 'b' ]):
723+ assert mpl .colors .same_color (text .get_color (), color )
724+
725+
647726def test_get_set_draggable ():
648727 legend = plt .legend ()
649728 assert not legend .get_draggable ()
0 commit comments