@@ -671,3 +671,72 @@ def test_no_warn_big_data_when_loc_specified():
671
671
ax .plot (np .arange (5000 ), label = idx )
672
672
legend = ax .legend ('best' )
673
673
fig .draw_artist (legend ) # Check that no warning is emitted.
674
+
675
+
676
+ def test_plot_multiple_input_multiple_label ():
677
+ # test ax.plot() with multidimensional input
678
+ # and multiple labels
679
+ x = [1 , 2 , 5 ]
680
+ y = [[2 , 4 , 3 ], [4 , 7 , 1 ], [3 , 9 , 2 ]]
681
+
682
+ label_arrays = [['one' , 'two' , 'three' ],
683
+ ('one' , 'two' , 'three' ),
684
+ np .array (['one' , 'two' , 'three' ])]
685
+
686
+ for label in label_arrays :
687
+ fig , ax = plt .subplots ()
688
+ ax .plot (x , y , label = label )
689
+ leg = ax .legend ()
690
+
691
+ assert len (leg .get_texts ()) == 3
692
+ assert leg .get_texts ()[0 ].get_text () == 'one'
693
+ assert leg .get_texts ()[1 ].get_text () == 'two'
694
+ assert leg .get_texts ()[2 ].get_text () == 'three'
695
+
696
+
697
+ def test_plot_multiple_input_single_label ():
698
+ # test ax.plot() with multidimensional input
699
+ # and single label
700
+ x = [1 , 2 , 5 ]
701
+ y = [[2 , 4 , 3 ], [4 , 7 , 1 ], [3 , 9 , 2 ]]
702
+ labels = ['one' , 1 , int ]
703
+
704
+ for label in labels :
705
+ fig , ax = plt .subplots ()
706
+ ax .plot (x , y , label = label )
707
+ leg = ax .legend ()
708
+
709
+ assert len (leg .get_texts ()) == 3
710
+ assert leg .get_texts ()[0 ].get_text () == str (label )
711
+ assert leg .get_texts ()[1 ].get_text () == str (label )
712
+ assert leg .get_texts ()[2 ].get_text () == str (label )
713
+
714
+
715
+ def test_plot_single_input_multiple_label ():
716
+ # test ax.plot() with 1D array like input
717
+ # and iterable label
718
+ x = [1 , 2 , 5 ]
719
+ y = [2 , 4 , 3 ]
720
+
721
+ label_arrays = [['one' , 'two' , 'three' ],
722
+ ('one' , 'two' , 'three' ),
723
+ np .array (['one' , 'two' , 'three' ])]
724
+
725
+ for label in label_arrays :
726
+ fig , ax = plt .subplots ()
727
+ ax .plot (x , y , label = label )
728
+ leg = ax .legend ()
729
+
730
+ assert len (leg .get_texts ()) == 1
731
+ assert leg .get_texts ()[0 ].get_text () == str (label )
732
+
733
+
734
+ def test_plot_multiple_label_incorrect_length_exception ():
735
+ # check that exception is raised for
736
+ # iterable label with incorrect length
737
+ with pytest .raises (Exception ):
738
+ x = [1 , 2 , 5 ]
739
+ y = [[2 , 4 , 3 ], [4 , 7 , 1 ], [3 , 9 , 2 ]]
740
+ label = ['one' , 'two' ]
741
+ fig , ax = plt .subplots ()
742
+ ax .plot (x , y , label = label )
0 commit comments