@@ -269,6 +269,34 @@ def test_hist_subplot_xrot(self):
269
269
)
270
270
self ._check_ticks_props (axes , xrot = 0 )
271
271
272
+ @pytest .mark .slow
273
+ @pytest .mark .parametrize ("column" , [None , "B" ])
274
+ @pytest .mark .parametrize ("label" , [None , "D" ])
275
+ def test_hist_with_legend (self , column , label ):
276
+ kwargs = {'legend' : True }
277
+ if label is not None :
278
+ kwargs ['label' ] = label
279
+ if column is not None :
280
+ kwargs ['column' ] = column
281
+
282
+ columns = ["A" , "B" ]
283
+ df = DataFrame (np .random .randn (30 , 2 ), columns = columns )
284
+ df ["C" ] = 15 * ["a" ] + 15 * ["b" ]
285
+ df = df .set_index ("C" )
286
+ _check_plot_works (df .hist , ** kwargs )
287
+ axes = df .hist (** kwargs )
288
+
289
+ axes_num = 2 if column is None else 1
290
+ layout = (1 , 2 ) if column is None else (1 , 1 )
291
+ self ._check_axes_shape (axes , axes_num = axes_num , layout = layout )
292
+
293
+ for labels , axis in zip (columns , axes [0 ]):
294
+ if column is not None :
295
+ labels = ["B" ]
296
+ if label is not None :
297
+ labels = ["D" ]
298
+ self ._check_legend_labels ([axis ], labels )
299
+
272
300
273
301
@td .skip_if_no_mpl
274
302
class TestDataFrameGroupByPlots (TestPlotBase ):
@@ -461,13 +489,27 @@ def test_axis_share_xy(self):
461
489
assert ax1 ._shared_y_axes .joined (ax1 , ax2 )
462
490
assert ax2 ._shared_y_axes .joined (ax1 , ax2 )
463
491
464
-
465
- @pytest .mark .slow
466
- @pytest .mark .parametrize ("by" , [None , "C" ])
467
- @pytest .mark .parametrize ("column" , [None , "B" ])
468
- @pytest .mark .parametrize ("label" , [None , "D" ])
469
- def test_hist_with_legend (by , column , label ):
470
- df = DataFrame (np .random .randn (30 , 2 ), columns = ["A" , "B" ])
471
- df ["C" ] = 15 * ["a" ] + 15 * ["b" ]
472
- df = df .set_index ("C" )
473
- _check_plot_works (df .hist , by = by , column = column , label = label , legend = True )
492
+ @pytest .mark .slow
493
+ @pytest .mark .parametrize ("column" , [None , "B" ])
494
+ @pytest .mark .parametrize ("label" , [None , "D" ])
495
+ def test_hist_with_legend (self , column , label ):
496
+ kwargs = {'legend' : True , "by" : "C" }
497
+ if label is not None :
498
+ kwargs ['label' ] = label
499
+ if column is not None :
500
+ kwargs ['column' ] = column
501
+
502
+ columns = ["A" , "B" ]
503
+ df = DataFrame (np .random .randn (30 , 2 ), columns = columns )
504
+ df ["C" ] = 15 * ["a" ] + 15 * ["b" ]
505
+ df = df .set_index ("C" )
506
+ _check_plot_works (df .hist , ** kwargs )
507
+ axes = df .hist (** kwargs )
508
+
509
+ self ._check_axes_shape (axes , axes_num = 2 , layout = (1 , 2 ))
510
+ labels = columns
511
+ if column is not None :
512
+ labels = ["B" ]
513
+ if label is not None :
514
+ labels = ["D" ]
515
+ self ._check_legend_labels (axes , labels )
0 commit comments