@@ -769,7 +769,7 @@ class MPLPlot(object):
769
769
_attr_defaults = {'logy' : False , 'logx' : False , 'loglog' : False ,
770
770
'mark_right' : True , 'stacked' : False }
771
771
772
- def __init__ (self , data , kind = None , by = None , subplots = False , sharex = True ,
772
+ def __init__ (self , data , kind = None , by = None , subplots = False , sharex = None ,
773
773
sharey = False , use_index = True ,
774
774
figsize = None , grid = None , legend = True , rot = None ,
775
775
ax = None , fig = None , title = None , xlim = None , ylim = None ,
@@ -786,7 +786,16 @@ def __init__(self, data, kind=None, by=None, subplots=False, sharex=True,
786
786
self .sort_columns = sort_columns
787
787
788
788
self .subplots = subplots
789
- self .sharex = sharex
789
+
790
+ if sharex is None :
791
+ if ax is None :
792
+ self .sharex = True
793
+ else :
794
+ # if we get an axis, the users should do the visibility setting...
795
+ self .sharex = False
796
+ else :
797
+ self .sharex = sharex
798
+
790
799
self .sharey = sharey
791
800
self .figsize = figsize
792
801
self .layout = layout
@@ -2350,10 +2359,14 @@ def _plot(data, x=None, y=None, subplots=False,
2350
2359
df_ax = """ax : matplotlib axes object, default None
2351
2360
subplots : boolean, default False
2352
2361
Make separate subplots for each column
2353
- sharex : boolean, default True
2354
- In case subplots=True, share x axis
2362
+ sharex : boolean, default True if ax is None else False
2363
+ In case subplots=True, share x axis and set some x axis labels to
2364
+ invisible; defaults to True if ax is None otherwise False if an ax
2365
+ is passed in; Be aware, that passing in both an ax and sharex=True
2366
+ will alter all x axis labels for all axis in a figure!
2355
2367
sharey : boolean, default False
2356
- In case subplots=True, share y axis
2368
+ In case subplots=True, share y axis and set some y axis labels to
2369
+ invisible
2357
2370
layout : tuple (optional)
2358
2371
(rows, columns) for the layout of subplots"""
2359
2372
series_ax = """ax : matplotlib axes object
@@ -2465,7 +2478,7 @@ def _plot(data, x=None, y=None, subplots=False,
2465
2478
2466
2479
@Appender (_shared_docs ['plot' ] % _shared_doc_df_kwargs )
2467
2480
def plot_frame (data , x = None , y = None , kind = 'line' , ax = None , # Dataframe unique
2468
- subplots = False , sharex = True , sharey = False , layout = None , # Dataframe unique
2481
+ subplots = False , sharex = None , sharey = False , layout = None , # Dataframe unique
2469
2482
figsize = None , use_index = True , title = None , grid = None ,
2470
2483
legend = True , style = None , logx = False , logy = False , loglog = False ,
2471
2484
xticks = None , yticks = None , xlim = None , ylim = None ,
@@ -2730,8 +2743,14 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
2730
2743
yrot : float, default None
2731
2744
rotation of y axis labels
2732
2745
ax : matplotlib axes object, default None
2733
- sharex : bool, if True, the X axis will be shared amongst all subplots.
2734
- sharey : bool, if True, the Y axis will be shared amongst all subplots.
2746
+ sharex : boolean, default True if ax is None else False
2747
+ In case subplots=True, share x axis and set some x axis labels to
2748
+ invisible; defaults to True if ax is None otherwise False if an ax
2749
+ is passed in; Be aware, that passing in both an ax and sharex=True
2750
+ will alter all x axis labels for all subplots in a figure!
2751
+ sharey : boolean, default False
2752
+ In case subplots=True, share y axis and set some y axis labels to
2753
+ invisible
2735
2754
figsize : tuple
2736
2755
The size of the figure to create in inches by default
2737
2756
layout: (optional) a tuple (rows, columns) for the layout of the histograms
@@ -3129,7 +3148,8 @@ def _subplots(naxes=None, sharex=False, sharey=False, squeeze=True,
3129
3148
Keyword arguments:
3130
3149
3131
3150
naxes : int
3132
- Number of required axes. Exceeded axes are set invisible. Default is nrows * ncols.
3151
+ Number of required axes. Exceeded axes are set invisible. Default is
3152
+ nrows * ncols.
3133
3153
3134
3154
sharex : bool
3135
3155
If True, the X axis will be shared amongst all subplots.
@@ -3256,12 +3276,12 @@ def _subplots(naxes=None, sharex=False, sharey=False, squeeze=True,
3256
3276
ax = fig .add_subplot (nrows , ncols , i + 1 , ** kwds )
3257
3277
axarr [i ] = ax
3258
3278
3259
- _handle_shared_axes (axarr , nplots , naxes , nrows , ncols , sharex , sharey )
3260
-
3261
3279
if naxes != nplots :
3262
3280
for ax in axarr [naxes :]:
3263
3281
ax .set_visible (False )
3264
3282
3283
+ _handle_shared_axes (axarr , nplots , naxes , nrows , ncols , sharex , sharey )
3284
+
3265
3285
if squeeze :
3266
3286
# Reshape the array to have the final desired dimension (nrow,ncol),
3267
3287
# though discarding unneeded dimensions that equal 1. If we only have
@@ -3276,44 +3296,64 @@ def _subplots(naxes=None, sharex=False, sharey=False, squeeze=True,
3276
3296
3277
3297
return fig , axes
3278
3298
3299
+ def _remove_xlabels_from_axis (ax ):
3300
+ for label in ax .get_xticklabels ():
3301
+ label .set_visible (False )
3302
+ try :
3303
+ # set_visible will not be effective if
3304
+ # minor axis has NullLocator and NullFormattor (default)
3305
+ import matplotlib .ticker as ticker
3306
+
3307
+ if isinstance (ax .xaxis .get_minor_locator (), ticker .NullLocator ):
3308
+ ax .xaxis .set_minor_locator (ticker .AutoLocator ())
3309
+ if isinstance (ax .xaxis .get_minor_formatter (), ticker .NullFormatter ):
3310
+ ax .xaxis .set_minor_formatter (ticker .FormatStrFormatter ('' ))
3311
+ for label in ax .get_xticklabels (minor = True ):
3312
+ label .set_visible (False )
3313
+ except Exception : # pragma no cover
3314
+ pass
3315
+ ax .xaxis .get_label ().set_visible (False )
3316
+
3317
+ def _remove_ylables_from_axis (ax ):
3318
+ for label in ax .get_yticklabels ():
3319
+ label .set_visible (False )
3320
+ try :
3321
+ import matplotlib .ticker as ticker
3322
+ if isinstance (ax .yaxis .get_minor_locator (), ticker .NullLocator ):
3323
+ ax .yaxis .set_minor_locator (ticker .AutoLocator ())
3324
+ if isinstance (ax .yaxis .get_minor_formatter (), ticker .NullFormatter ):
3325
+ ax .yaxis .set_minor_formatter (ticker .FormatStrFormatter ('' ))
3326
+ for label in ax .get_yticklabels (minor = True ):
3327
+ label .set_visible (False )
3328
+ except Exception : # pragma no cover
3329
+ pass
3330
+ ax .yaxis .get_label ().set_visible (False )
3279
3331
3280
3332
def _handle_shared_axes (axarr , nplots , naxes , nrows , ncols , sharex , sharey ):
3281
3333
if nplots > 1 :
3282
3334
3335
+ # first find out the ax layout, so that we can correctly handle 'gaps"
3336
+ layout = np .zeros ((nrows + 1 ,ncols + 1 ), dtype = np .bool )
3337
+ for ax in axarr :
3338
+ layout [ax .rowNum , ax .colNum ] = ax .get_visible ()
3339
+
3283
3340
if sharex and nrows > 1 :
3284
- for ax in axarr [:naxes ][:- ncols ]: # only bottom row
3285
- for label in ax .get_xticklabels ():
3286
- label .set_visible (False )
3287
- try :
3288
- # set_visible will not be effective if
3289
- # minor axis has NullLocator and NullFormattor (default)
3290
- import matplotlib .ticker as ticker
3291
-
3292
- if isinstance (ax .xaxis .get_minor_locator (), ticker .NullLocator ):
3293
- ax .xaxis .set_minor_locator (ticker .AutoLocator ())
3294
- if isinstance (ax .xaxis .get_minor_formatter (), ticker .NullFormatter ):
3295
- ax .xaxis .set_minor_formatter (ticker .FormatStrFormatter ('' ))
3296
- for label in ax .get_xticklabels (minor = True ):
3297
- label .set_visible (False )
3298
- except Exception : # pragma no cover
3299
- pass
3300
- ax .xaxis .get_label ().set_visible (False )
3341
+ for ax in axarr :
3342
+ # only the last row of subplots should get x labels -> all other off
3343
+ # layout handles the case that the subplot is the last in the column,
3344
+ # because below is no subplot/gap.
3345
+ if not layout [ax .rowNum + 1 , ax .colNum ]:
3346
+ continue
3347
+ _remove_xlabels_from_axis (ax )
3301
3348
if sharey and ncols > 1 :
3302
- for i , ax in enumerate (axarr ):
3303
- if (i % ncols ) != 0 : # only first column
3304
- for label in ax .get_yticklabels ():
3305
- label .set_visible (False )
3306
- try :
3307
- import matplotlib .ticker as ticker
3308
- if isinstance (ax .yaxis .get_minor_locator (), ticker .NullLocator ):
3309
- ax .yaxis .set_minor_locator (ticker .AutoLocator ())
3310
- if isinstance (ax .yaxis .get_minor_formatter (), ticker .NullFormatter ):
3311
- ax .yaxis .set_minor_formatter (ticker .FormatStrFormatter ('' ))
3312
- for label in ax .get_yticklabels (minor = True ):
3313
- label .set_visible (False )
3314
- except Exception : # pragma no cover
3315
- pass
3316
- ax .yaxis .get_label ().set_visible (False )
3349
+ for ax in axarr :
3350
+ # only the first column should get y labels -> set all other to off
3351
+ # as we only have labels in teh first column and we always have a subplot there,
3352
+ # we can skip the layout test
3353
+ if ax .is_first_col ():
3354
+ continue
3355
+ _remove_ylables_from_axis (ax )
3356
+
3317
3357
3318
3358
3319
3359
def _flatten (axes ):
0 commit comments