(
n_cells,
ncols,
nrows="auto",
title=False,
size=1.3,
sharex=False,
sharey=False,
)
| 422 | |
| 423 | |
| 424 | def _prepare_trellis( |
| 425 | n_cells, |
| 426 | ncols, |
| 427 | nrows="auto", |
| 428 | title=False, |
| 429 | size=1.3, |
| 430 | sharex=False, |
| 431 | sharey=False, |
| 432 | ): |
| 433 | from matplotlib.gridspec import GridSpec |
| 434 | |
| 435 | from ._mpl_figure import _figure |
| 436 | |
| 437 | if n_cells == 1: |
| 438 | nrows = ncols = 1 |
| 439 | elif isinstance(ncols, int) and n_cells <= ncols: |
| 440 | nrows, ncols = 1, n_cells |
| 441 | else: |
| 442 | if ncols == "auto" and nrows == "auto": |
| 443 | nrows = math.floor(math.sqrt(n_cells)) |
| 444 | ncols = math.ceil(n_cells / nrows) |
| 445 | elif ncols == "auto": |
| 446 | ncols = math.ceil(n_cells / nrows) |
| 447 | elif nrows == "auto": |
| 448 | nrows = math.ceil(n_cells / ncols) |
| 449 | else: |
| 450 | naxes = ncols * nrows |
| 451 | if naxes < n_cells: |
| 452 | raise ValueError( |
| 453 | f"Cannot plot {n_cells} axes in a {nrows} by {ncols} figure." |
| 454 | ) |
| 455 | |
| 456 | width = size * ncols |
| 457 | height = (size + max(0, 0.1 * (4 - size))) * nrows + bool(title) * 0.5 |
| 458 | fig = _figure(toolbar=False, figsize=(width * 1.5, 0.25 + height * 1.5)) |
| 459 | gs = GridSpec(nrows, ncols, figure=fig) |
| 460 | |
| 461 | axes = [] |
| 462 | for ax_idx in range(n_cells): |
| 463 | subplot_kw = dict() |
| 464 | if ax_idx > 0: |
| 465 | if sharex: |
| 466 | subplot_kw.update(sharex=axes[0]) |
| 467 | if sharey: |
| 468 | subplot_kw.update(sharey=axes[0]) |
| 469 | axes.append(fig.add_subplot(gs[ax_idx], **subplot_kw)) |
| 470 | |
| 471 | return fig, axes, ncols, nrows |
| 472 | |
| 473 | |
| 474 | def _draw_proj_checkbox(event, params, draw_current_state=True): |
no test coverage detected