@@ -3363,6 +3363,62 @@ def test_colors_of_columns_with_same_name(self):
3363
3363
for legend , line in zip (result .get_legend ().legendHandles , result .lines ):
3364
3364
assert legend .get_color () == line .get_color ()
3365
3365
3366
+ @pytest .mark .parametrize (
3367
+ "index_name, old_label, new_label" ,
3368
+ [
3369
+ (None , "" , "new" ),
3370
+ ("old" , "old" , "new" ),
3371
+ (None , "" , "" ),
3372
+ (None , "" , 1 ),
3373
+ (None , "" , [1 , 2 ]),
3374
+ ],
3375
+ )
3376
+ @pytest .mark .parametrize ("kind" , ["line" , "area" , "bar" ])
3377
+ def test_xlabel_ylabel_dataframe_single_plot (
3378
+ self , kind , index_name , old_label , new_label
3379
+ ):
3380
+ # GH 9093
3381
+ df = pd .DataFrame ([[1 , 2 ], [2 , 5 ]], columns = ["Type A" , "Type B" ])
3382
+ df .index .name = index_name
3383
+
3384
+ # default is the ylabel is not shown and xlabel is index name
3385
+ ax = df .plot (kind = kind )
3386
+ assert ax .get_xlabel () == old_label
3387
+ assert ax .get_ylabel () == ""
3388
+
3389
+ # old xlabel will be overriden and assigned ylabel will be used as ylabel
3390
+ ax = df .plot (kind = kind , ylabel = new_label , xlabel = new_label )
3391
+ assert ax .get_ylabel () == str (new_label )
3392
+ assert ax .get_xlabel () == str (new_label )
3393
+
3394
+ @pytest .mark .parametrize (
3395
+ "index_name, old_label, new_label" ,
3396
+ [
3397
+ (None , "" , "new" ),
3398
+ ("old" , "old" , "new" ),
3399
+ (None , "" , "" ),
3400
+ (None , "" , 1 ),
3401
+ (None , "" , [1 , 2 ]),
3402
+ ],
3403
+ )
3404
+ @pytest .mark .parametrize ("kind" , ["line" , "area" , "bar" ])
3405
+ def test_xlabel_ylabel_dataframe_subplots (
3406
+ self , kind , index_name , old_label , new_label
3407
+ ):
3408
+ # GH 9093
3409
+ df = pd .DataFrame ([[1 , 2 ], [2 , 5 ]], columns = ["Type A" , "Type B" ])
3410
+ df .index .name = index_name
3411
+
3412
+ # default is the ylabel is not shown and xlabel is index name
3413
+ axes = df .plot (kind = kind , subplots = True )
3414
+ assert all (ax .get_ylabel () == "" for ax in axes )
3415
+ assert all (ax .get_xlabel () == old_label for ax in axes )
3416
+
3417
+ # old xlabel will be overriden and assigned ylabel will be used as ylabel
3418
+ axes = df .plot (kind = kind , ylabel = new_label , xlabel = new_label , subplots = True )
3419
+ assert all (ax .get_ylabel () == str (new_label ) for ax in axes )
3420
+ assert all (ax .get_xlabel () == str (new_label ) for ax in axes )
3421
+
3366
3422
3367
3423
def _generate_4_axes_via_gridspec ():
3368
3424
import matplotlib .pyplot as plt
0 commit comments