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

Function _infer_interval_breaks

xarray/plot/utils.py:857–903  ·  view source on GitHub ↗

>>> _infer_interval_breaks(np.arange(5)) array([-0.5, 0.5, 1.5, 2.5, 3.5, 4.5]) >>> _infer_interval_breaks([[0, 1], [3, 4]], axis=1) array([[-0.5, 0.5, 1.5], [ 2.5, 3.5, 4.5]]) >>> _infer_interval_breaks(np.logspace(-2, 2, 5), scale="log") array([3.162277

(coord, axis=0, scale=None, check_monotonic=False)

Source from the content-addressed store, hash-verified

855
856
857def _infer_interval_breaks(coord, axis=0, scale=None, check_monotonic=False):
858 """
859 >>> _infer_interval_breaks(np.arange(5))
860 array([-0.5, 0.5, 1.5, 2.5, 3.5, 4.5])
861 >>> _infer_interval_breaks([[0, 1], [3, 4]], axis=1)
862 array([[-0.5, 0.5, 1.5],
863 [ 2.5, 3.5, 4.5]])
864 >>> _infer_interval_breaks(np.logspace(-2, 2, 5), scale="log")
865 array([3.16227766e-03, 3.16227766e-02, 3.16227766e-01, 3.16227766e+00,
866 3.16227766e+01, 3.16227766e+02])
867 """
868 coord = np.asarray(coord)
869
870 if check_monotonic and not _is_monotonic(coord, axis=axis):
871 raise ValueError(
872 "The input coordinate is not sorted in increasing "
873 f"order along axis {axis}. This can lead to unexpected "
874 "results. Consider calling the `sortby` method on "
875 "the input DataArray. To plot data with categorical "
876 "axes, consider using the `heatmap` function from "
877 "the `seaborn` statistical plotting library."
878 )
879
880 # If logscale, compute the intervals in the logarithmic space
881 if scale == "log":
882 if (coord <= 0).any():
883 raise ValueError(
884 "Found negative or zero value in coordinates. "
885 "Coordinates must be positive on logscale plots."
886 )
887 coord = np.log10(coord)
888
889 deltas = 0.5 * np.diff(coord, axis=axis)
890 if deltas.size == 0:
891 deltas = np.array(0.0)
892 first = np.take(coord, [0], axis=axis) - np.take(deltas, [0], axis=axis)
893 last = np.take(coord, [-1], axis=axis) + np.take(deltas, [-1], axis=axis)
894 trim_last = tuple(
895 slice(None, -1) if n == axis else slice(None) for n in range(coord.ndim)
896 )
897 interval_breaks = np.concatenate(
898 [first, coord[trim_last] + deltas, last], axis=axis
899 )
900 if scale == "log":
901 # Recovert the intervals into the linear space
902 return np.power(10, interval_breaks)
903 return interval_breaks
904
905
906def _process_cmap_cbar_kwargs(

Calls 3

_is_monotonicFunction · 0.85
anyMethod · 0.45
diffMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…