MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / index_of

Function index_of

lib/matplotlib/cbook.py:1741–1773  ·  view source on GitHub ↗

A helper function to create reasonable x values for the given *y*. This is used for plotting (x, y) if x values are not explicitly given. First try ``y.index`` (assuming *y* is a `pandas.Series`), if that fails, use ``range(len(y))``. This will be extended in the future to de

(y)

Source from the content-addressed store, hash-verified

1739
1740
1741def index_of(y):
1742 """
1743 A helper function to create reasonable x values for the given *y*.
1744
1745 This is used for plotting (x, y) if x values are not explicitly given.
1746
1747 First try ``y.index`` (assuming *y* is a `pandas.Series`), if that
1748 fails, use ``range(len(y))``.
1749
1750 This will be extended in the future to deal with more types of
1751 labeled data.
1752
1753 Parameters
1754 ----------
1755 y : float or array-like
1756
1757 Returns
1758 -------
1759 x, y : ndarray
1760 The x and y values to plot.
1761 """
1762 try:
1763 return y.index.to_numpy(), y.to_numpy()
1764 except AttributeError:
1765 pass
1766 try:
1767 y = _check_1d(y)
1768 except (VisibleDeprecationWarning, ValueError):
1769 # NumPy 1.19 will warn on ragged input, and we can't actually use it.
1770 pass
1771 else:
1772 return np.arange(y.shape[0], dtype=float), y
1773 raise ValueError('Input could not be cast to an at-least-1D NumPy array')
1774
1775
1776def safe_first_element(obj):

Callers 1

_plot_argsMethod · 0.90

Calls 1

_check_1dFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…