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