(
figsize: Iterable[float] | None = None,
size: float | None = None,
aspect: AspectOptions = None,
ax: Axes | None = None,
**subplot_kws: Any,
)
| 456 | |
| 457 | |
| 458 | def get_axis( |
| 459 | figsize: Iterable[float] | None = None, |
| 460 | size: float | None = None, |
| 461 | aspect: AspectOptions = None, |
| 462 | ax: Axes | None = None, |
| 463 | **subplot_kws: Any, |
| 464 | ) -> Axes: |
| 465 | if TYPE_CHECKING: |
| 466 | import matplotlib as mpl |
| 467 | import matplotlib.pyplot as plt |
| 468 | else: |
| 469 | mpl = attempt_import("matplotlib") |
| 470 | plt = attempt_import("matplotlib.pyplot") |
| 471 | |
| 472 | if figsize is not None: |
| 473 | if ax is not None: |
| 474 | raise ValueError("cannot provide both `figsize` and `ax` arguments") |
| 475 | if size is not None: |
| 476 | raise ValueError("cannot provide both `figsize` and `size` arguments") |
| 477 | _, ax = plt.subplots(figsize=figsize, subplot_kw=subplot_kws) |
| 478 | return ax |
| 479 | |
| 480 | if size is not None: |
| 481 | if ax is not None: |
| 482 | raise ValueError("cannot provide both `size` and `ax` arguments") |
| 483 | if aspect is None or aspect == "auto": |
| 484 | width, height = mpl.rcParams["figure.figsize"] |
| 485 | faspect = width / height |
| 486 | elif aspect == "equal": |
| 487 | faspect = 1 |
| 488 | else: |
| 489 | faspect = aspect |
| 490 | figsize = (size * faspect, size) |
| 491 | _, ax = plt.subplots(figsize=figsize, subplot_kw=subplot_kws) |
| 492 | return ax |
| 493 | |
| 494 | if aspect is not None: |
| 495 | raise ValueError("cannot provide `aspect` argument without `size`") |
| 496 | |
| 497 | if subplot_kws and ax is not None: |
| 498 | raise ValueError("cannot use subplot_kws with existing ax") |
| 499 | |
| 500 | if ax is None: |
| 501 | ax = _maybe_gca(**subplot_kws) |
| 502 | |
| 503 | return ax |
| 504 | |
| 505 | |
| 506 | def _maybe_gca(**subplot_kws: Any) -> Axes: |
searching dependent graphs…