Skip to content

Commit a36f007

Browse files
committed
Undo tools change
1 parent 8401799 commit a36f007

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

pandas/plotting/_matplotlib/tools.py

+14-20
Original file line numberDiff line numberDiff line change
@@ -390,50 +390,44 @@ def handle_shared_axes(
390390
sharey: bool,
391391
) -> None:
392392
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+
393398
if nrows > 1:
394399
try:
395400
# first find out the ax layout,
396401
# so that we can correctly handle 'gaps"
397402
layout = np.zeros((nrows + 1, ncols + 1), dtype=np.bool_)
398403
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()
404405

405406
for ax in axarr:
406-
spec = ax.get_subplotspec()
407-
if spec is None:
408-
continue
409407
# only the last row of subplots should get x labels -> all
410408
# other off layout handles the case that the subplot is
411409
# 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)]:
413411
continue
414412
if sharex or _has_externally_shared_axis(ax, "x"):
415413
_remove_labels_from_axis(ax.xaxis)
416414

417415
except IndexError:
418416
# if gridspec is used, ax.rowNum and ax.colNum may different
419417
# 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)
427424

428425
if ncols > 1:
429426
for ax in axarr:
430-
spec = ax.get_subplotspec()
431-
if spec is None:
432-
continue
433427
# only the first column should get y labels -> set all other to
434428
# off as we only have labels in the first column and we always
435429
# have a subplot there, we can skip the layout test
436-
if spec.is_first_col():
430+
if is_first_col(ax):
437431
continue
438432
if sharey or _has_externally_shared_axis(ax, "y"):
439433
_remove_labels_from_axis(ax.yaxis)

0 commit comments

Comments
 (0)