@@ -2478,23 +2478,12 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
2478
2478
kwds : other plotting keyword arguments
2479
2479
To be passed to hist function
2480
2480
"""
2481
- import matplotlib .pyplot as plt
2482
2481
2483
2482
if by is not None :
2484
2483
axes = grouped_hist (data , column = column , by = by , ax = ax , grid = grid , figsize = figsize ,
2485
2484
sharex = sharex , sharey = sharey , layout = layout , bins = bins ,
2485
+ xlabelsize = xlabelsize , xrot = xrot , ylabelsize = ylabelsize , yrot = yrot ,
2486
2486
** kwds )
2487
-
2488
- for ax in axes .ravel ():
2489
- if xlabelsize is not None :
2490
- plt .setp (ax .get_xticklabels (), fontsize = xlabelsize )
2491
- if xrot is not None :
2492
- plt .setp (ax .get_xticklabels (), rotation = xrot )
2493
- if ylabelsize is not None :
2494
- plt .setp (ax .get_yticklabels (), fontsize = ylabelsize )
2495
- if yrot is not None :
2496
- plt .setp (ax .get_yticklabels (), rotation = yrot )
2497
-
2498
2487
return axes
2499
2488
2500
2489
if column is not None :
@@ -2510,21 +2499,12 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
2510
2499
2511
2500
for i , col in enumerate (com ._try_sort (data .columns )):
2512
2501
ax = axes [i // ncols , i % ncols ]
2513
- ax .xaxis .set_visible (True )
2514
- ax .yaxis .set_visible (True )
2515
2502
ax .hist (data [col ].dropna ().values , bins = bins , ** kwds )
2516
2503
ax .set_title (col )
2517
2504
ax .grid (grid )
2518
2505
2519
- if xlabelsize is not None :
2520
- plt .setp (ax .get_xticklabels (), fontsize = xlabelsize )
2521
- if xrot is not None :
2522
- plt .setp (ax .get_xticklabels (), rotation = xrot )
2523
- if ylabelsize is not None :
2524
- plt .setp (ax .get_yticklabels (), fontsize = ylabelsize )
2525
- if yrot is not None :
2526
- plt .setp (ax .get_yticklabels (), rotation = yrot )
2527
-
2506
+ _set_ticks_props (axes , xlabelsize = xlabelsize , xrot = xrot ,
2507
+ ylabelsize = ylabelsize , yrot = yrot )
2528
2508
fig .subplots_adjust (wspace = 0.3 , hspace = 0.3 )
2529
2509
2530
2510
return axes
@@ -2584,23 +2564,18 @@ def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
2584
2564
ax .hist (values , bins = bins , ** kwds )
2585
2565
ax .grid (grid )
2586
2566
axes = np .array ([ax ])
2567
+
2568
+ _set_ticks_props (axes , xlabelsize = xlabelsize , xrot = xrot ,
2569
+ ylabelsize = ylabelsize , yrot = yrot )
2570
+
2587
2571
else :
2588
2572
if 'figure' in kwds :
2589
2573
raise ValueError ("Cannot pass 'figure' when using the "
2590
2574
"'by' argument, since a new 'Figure' instance "
2591
2575
"will be created" )
2592
- axes = grouped_hist (self , by = by , ax = ax , grid = grid , figsize = figsize ,
2593
- bins = bins , ** kwds )
2594
-
2595
- for ax in axes .ravel ():
2596
- if xlabelsize is not None :
2597
- plt .setp (ax .get_xticklabels (), fontsize = xlabelsize )
2598
- if xrot is not None :
2599
- plt .setp (ax .get_xticklabels (), rotation = xrot )
2600
- if ylabelsize is not None :
2601
- plt .setp (ax .get_yticklabels (), fontsize = ylabelsize )
2602
- if yrot is not None :
2603
- plt .setp (ax .get_yticklabels (), rotation = yrot )
2576
+ axes = grouped_hist (self , by = by , ax = ax , grid = grid , figsize = figsize , bins = bins ,
2577
+ xlabelsize = xlabelsize , xrot = xrot , ylabelsize = ylabelsize , yrot = yrot ,
2578
+ ** kwds )
2604
2579
2605
2580
if axes .ndim == 1 and len (axes ) == 1 :
2606
2581
return axes [0 ]
@@ -2609,6 +2584,7 @@ def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
2609
2584
2610
2585
def grouped_hist (data , column = None , by = None , ax = None , bins = 50 , figsize = None ,
2611
2586
layout = None , sharex = False , sharey = False , rot = 90 , grid = True ,
2587
+ xlabelsize = None , xrot = None , ylabelsize = None , yrot = None ,
2612
2588
** kwargs ):
2613
2589
"""
2614
2590
Grouped histogram
@@ -2635,9 +2611,15 @@ def grouped_hist(data, column=None, by=None, ax=None, bins=50, figsize=None,
2635
2611
def plot_group (group , ax ):
2636
2612
ax .hist (group .dropna ().values , bins = bins , ** kwargs )
2637
2613
2614
+ xrot = xrot or rot
2615
+
2638
2616
fig , axes = _grouped_plot (plot_group , data , column = column ,
2639
2617
by = by , sharex = sharex , sharey = sharey ,
2640
2618
figsize = figsize , layout = layout , rot = rot )
2619
+
2620
+ _set_ticks_props (axes , xlabelsize = xlabelsize , xrot = xrot ,
2621
+ ylabelsize = ylabelsize , yrot = yrot )
2622
+
2641
2623
fig .subplots_adjust (bottom = 0.15 , top = 0.9 , left = 0.1 , right = 0.9 ,
2642
2624
hspace = 0.5 , wspace = 0.3 )
2643
2625
return axes
@@ -3044,6 +3026,22 @@ def _get_xlim(lines):
3044
3026
return left , right
3045
3027
3046
3028
3029
+ def _set_ticks_props (axes , xlabelsize = None , xrot = None ,
3030
+ ylabelsize = None , yrot = None ):
3031
+ import matplotlib .pyplot as plt
3032
+
3033
+ for ax in _flatten (axes ):
3034
+ if xlabelsize is not None :
3035
+ plt .setp (ax .get_xticklabels (), fontsize = xlabelsize )
3036
+ if xrot is not None :
3037
+ plt .setp (ax .get_xticklabels (), rotation = xrot )
3038
+ if ylabelsize is not None :
3039
+ plt .setp (ax .get_yticklabels (), fontsize = ylabelsize )
3040
+ if yrot is not None :
3041
+ plt .setp (ax .get_yticklabels (), rotation = yrot )
3042
+ return axes
3043
+
3044
+
3047
3045
if __name__ == '__main__' :
3048
3046
# import pandas.rpy.common as com
3049
3047
# sales = com.load_data('sanfrancisco.home.sales', package='nutshell')
0 commit comments