@@ -390,50 +390,44 @@ def handle_shared_axes(
390
390
sharey : bool ,
391
391
) -> None :
392
392
if nplots > 1 :
393
+ row_num = lambda x : x .get_subplotspec ().rowspan .start
394
+ col_num = lambda x : x .get_subplotspec ().colspan .start
395
+
396
+ is_first_col = lambda x : x .get_subplotspec ().is_first_col ()
397
+
393
398
if nrows > 1 :
394
399
try :
395
400
# first find out the ax layout,
396
401
# so that we can correctly handle 'gaps"
397
402
layout = np .zeros ((nrows + 1 , ncols + 1 ), dtype = np .bool_ )
398
403
for ax in axarr :
399
- spec = ax .get_subplotspec ()
400
- if spec is not None :
401
- layout [
402
- spec .rowspan .start , spec .colspan .start
403
- ] = ax .get_visible ()
404
+ layout [row_num (ax ), col_num (ax )] = ax .get_visible ()
404
405
405
406
for ax in axarr :
406
- spec = ax .get_subplotspec ()
407
- if spec is None :
408
- continue
409
407
# only the last row of subplots should get x labels -> all
410
408
# other off layout handles the case that the subplot is
411
409
# the last in the column, because below is no subplot/gap.
412
- if not layout [spec . rowspan . start + 1 , spec . colspan . start ]:
410
+ if not layout [row_num ( ax ) + 1 , col_num ( ax ) ]:
413
411
continue
414
412
if sharex or _has_externally_shared_axis (ax , "x" ):
415
413
_remove_labels_from_axis (ax .xaxis )
416
414
417
415
except IndexError :
418
416
# if gridspec is used, ax.rowNum and ax.colNum may different
419
417
# from layout shape. in this case, use last_row logic
420
- spec = ax .get_subplotspec ()
421
- if spec is not None :
422
- for ax in axarr :
423
- if spec .is_last_row ():
424
- continue
425
- if sharex or _has_externally_shared_axis (ax , "x" ):
426
- _remove_labels_from_axis (ax .xaxis )
418
+ is_last_row = lambda x : x .get_subplotspec ().is_last_row ()
419
+ for ax in axarr :
420
+ if is_last_row (ax ):
421
+ continue
422
+ if sharex or _has_externally_shared_axis (ax , "x" ):
423
+ _remove_labels_from_axis (ax .xaxis )
427
424
428
425
if ncols > 1 :
429
426
for ax in axarr :
430
- spec = ax .get_subplotspec ()
431
- if spec is None :
432
- continue
433
427
# only the first column should get y labels -> set all other to
434
428
# off as we only have labels in the first column and we always
435
429
# have a subplot there, we can skip the layout test
436
- if spec . is_first_col ():
430
+ if is_first_col (ax ):
437
431
continue
438
432
if sharey or _has_externally_shared_axis (ax , "y" ):
439
433
_remove_labels_from_axis (ax .yaxis )
0 commit comments