@@ -534,6 +534,66 @@ def test_legend_title_fontsize():
534534 assert leg .get_title ().get_fontsize () == 22
535535
536536
537+ def test_legend_labelcolor_single ():
538+ # test labelcolor for a single color
539+ fig , ax = plt .subplots ()
540+ ax .plot (np .arange (10 ), np .arange (10 )* 1 , label = '#1' )
541+ ax .plot (np .arange (10 ), np .arange (10 )* 2 , label = '#2' )
542+ ax .plot (np .arange (10 ), np .arange (10 )* 3 , label = '#3' )
543+
544+ leg = ax .legend (labelcolor = 'red' )
545+ for text in leg .get_texts ():
546+ assert mpl .colors .same_color (text .get_color (), 'red' )
547+
548+
549+ def test_legend_labelcolor_list ():
550+ # test labelcolor for a list of colors
551+ fig , ax = plt .subplots ()
552+ ax .plot (np .arange (10 ), np .arange (10 )* 1 , label = '#1' )
553+ ax .plot (np .arange (10 ), np .arange (10 )* 2 , label = '#2' )
554+ ax .plot (np .arange (10 ), np .arange (10 )* 3 , label = '#3' )
555+
556+ leg = ax .legend (labelcolor = ['r' , 'g' , 'b' ])
557+ for text , color in zip (leg .get_texts (), ['r' , 'g' , 'b' ]):
558+ assert mpl .colors .same_color (text .get_color (), color )
559+
560+
561+ def test_legend_labelcolor_linecolor ():
562+ # test the labelcolor for labelcolor='linecolor'
563+ fig , ax = plt .subplots ()
564+ ax .plot (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , color = 'r' )
565+ ax .plot (np .arange (10 ), np .arange (10 )* 2 , label = '#2' , color = 'g' )
566+ ax .plot (np .arange (10 ), np .arange (10 )* 3 , label = '#3' , color = 'b' )
567+
568+ leg = ax .legend (labelcolor = 'linecolor' )
569+ for text , color in zip (leg .get_texts (), ['r' , 'g' , 'b' ]):
570+ assert mpl .colors .same_color (text .get_color (), color )
571+
572+
573+ def test_legend_labelcolor_markeredgecolor ():
574+ # test the labelcolor for labelcolor='markeredgecolor'
575+ fig , ax = plt .subplots ()
576+ ax .plot (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , markeredgecolor = 'r' )
577+ ax .plot (np .arange (10 ), np .arange (10 )* 2 , label = '#2' , markeredgecolor = 'g' )
578+ ax .plot (np .arange (10 ), np .arange (10 )* 3 , label = '#3' , markeredgecolor = 'b' )
579+
580+ leg = ax .legend (labelcolor = 'markeredgecolor' )
581+ for text , color in zip (leg .get_texts (), ['r' , 'g' , 'b' ]):
582+ assert mpl .colors .same_color (text .get_color (), color )
583+
584+
585+ def test_legend_labelcolor_markerfacecolor ():
586+ # test the labelcolor for labelcolor='markerfacecolor'
587+ fig , ax = plt .subplots ()
588+ ax .plot (np .arange (10 ), np .arange (10 )* 1 , label = '#1' , markerfacecolor = 'r' )
589+ ax .plot (np .arange (10 ), np .arange (10 )* 2 , label = '#2' , markerfacecolor = 'g' )
590+ ax .plot (np .arange (10 ), np .arange (10 )* 3 , label = '#3' , markerfacecolor = 'b' )
591+
592+ leg = ax .legend (labelcolor = 'markerfacecolor' )
593+ for text , color in zip (leg .get_texts (), ['r' , 'g' , 'b' ]):
594+ assert mpl .colors .same_color (text .get_color (), color )
595+
596+
537597def test_get_set_draggable ():
538598 legend = plt .legend ()
539599 assert not legend .get_draggable ()
0 commit comments