MCPcopy Index your code
hub / github.com/pydata/xarray / get_axis

Function get_axis

xarray/plot/utils.py:458–503  ·  view source on GitHub ↗
(
    figsize: Iterable[float] | None = None,
    size: float | None = None,
    aspect: AspectOptions = None,
    ax: Axes | None = None,
    **subplot_kws: Any,
)

Source from the content-addressed store, hash-verified

456
457
458def 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
506def _maybe_gca(**subplot_kws: Any) -> Axes:

Callers 8

newplotfuncFunction · 0.90
lineFunction · 0.90
histFunction · 0.90
newplotfuncFunction · 0.90
test_get_axis_raisesFunction · 0.90
test_get_axisFunction · 0.90
test_get_axis_cartopyFunction · 0.90
test_get_axis_currentFunction · 0.90

Calls 2

attempt_importFunction · 0.90
_maybe_gcaFunction · 0.85

Tested by 4

test_get_axis_raisesFunction · 0.72
test_get_axisFunction · 0.72
test_get_axis_cartopyFunction · 0.72
test_get_axis_currentFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…