MCPcopy
hub / github.com/pydata/xarray / _guess_coords_to_plot

Function _guess_coords_to_plot

xarray/plot/utils.py:1755–1843  ·  view source on GitHub ↗

Guess what coords to plot if some of the values in coords_to_plot are None which happens when the user has not defined all available ways of visualizing the data. Parameters ---------- darray : DataArray The DataArray to check for available coords. coords_to_plo

(
    darray: DataArray,
    coords_to_plot: MutableMapping[str, Hashable | None],
    kwargs: dict,
    default_guess: tuple[str, ...] = ("x",),
    # TODO: Can this be normalized, plt.cbook.normalize_kwargs?
    ignore_guess_kwargs: tuple[tuple[str, ...], ...] = ((),),
)

Source from the content-addressed store, hash-verified

1753
1754
1755def _guess_coords_to_plot(
1756 darray: DataArray,
1757 coords_to_plot: MutableMapping[str, Hashable | None],
1758 kwargs: dict,
1759 default_guess: tuple[str, ...] = ("x",),
1760 # TODO: Can this be normalized, plt.cbook.normalize_kwargs?
1761 ignore_guess_kwargs: tuple[tuple[str, ...], ...] = ((),),
1762) -> MutableMapping[str, Hashable]:
1763 """
1764 Guess what coords to plot if some of the values in coords_to_plot are None which
1765 happens when the user has not defined all available ways of visualizing
1766 the data.
1767
1768 Parameters
1769 ----------
1770 darray : DataArray
1771 The DataArray to check for available coords.
1772 coords_to_plot : MutableMapping[str, Hashable]
1773 Coords defined by the user to plot.
1774 kwargs : dict
1775 Extra kwargs that will be sent to matplotlib.
1776 default_guess : Iterable[str], optional
1777 Default values and order to retrieve dims if values in dims_plot is
1778 missing, default: ("x", "hue", "size").
1779 ignore_guess_kwargs : tuple[tuple[str, ...], ...]
1780 Matplotlib arguments to ignore.
1781
1782 Examples
1783 --------
1784 >>> ds = xr.tutorial.scatter_example_dataset(seed=42)
1785 >>> # Only guess x by default:
1786 >>> xr.plot.utils._guess_coords_to_plot(
1787 ... ds.A,
1788 ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None},
1789 ... kwargs={},
1790 ... )
1791 {'x': 'x', 'z': None, 'hue': None, 'size': None}
1792
1793 >>> # Guess all plot dims with other default values:
1794 >>> xr.plot.utils._guess_coords_to_plot(
1795 ... ds.A,
1796 ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None},
1797 ... kwargs={},
1798 ... default_guess=("x", "hue", "size"),
1799 ... ignore_guess_kwargs=((), ("c", "color"), ("s",)),
1800 ... )
1801 {'x': 'x', 'z': None, 'hue': 'y', 'size': 'z'}
1802
1803 >>> # Don't guess ´size´, since the matplotlib kwarg ´s´ has been defined:
1804 >>> xr.plot.utils._guess_coords_to_plot(
1805 ... ds.A,
1806 ... coords_to_plot={"x": None, "z": None, "hue": None, "size": None},
1807 ... kwargs={"s": 5},
1808 ... default_guess=("x", "hue", "size"),
1809 ... ignore_guess_kwargs=((), ("c", "color"), ("s",)),
1810 ... )
1811 {'x': 'x', 'z': None, 'hue': 'y', 'size': None}
1812

Callers 2

newplotfuncFunction · 0.90
map_plot1dMethod · 0.90

Calls 5

_assert_valid_xyFunction · 0.85
itemsMethod · 0.80
keysMethod · 0.80
valuesMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…