matplotlib/matplotlib · error · ValueError

Input array must be in the range [0, 1]. Found a minimum val

Error message

Input array must be in the range [0, 1]. Found a minimum value of {arr.min()}

What it means

Error "Input array must be in the range [0, 1]. Found a minimum value of {arr.min()}" thrown in matplotlib/matplotlib.

Source

Thrown at lib/matplotlib/colors.py:3685

                         f"shape {arr.shape} was found.")

    in_shape = arr.shape
    # ensure numerics are done at least on float32; ints are cast as well
    arr = np.asarray(arr, dtype=np.promote_types(arr.dtype, np.float32))
    if arr.ndim == 1:
        arr = np.expand_dims(arr, axis=0)  # ensure arr is 2D

    out = np.zeros_like(arr)
    arr_max = arr.max(-1)
    # Check if input is in the expected range
    if np.any(arr_max > 1):
        raise ValueError(
            "Input array must be in the range [0, 1]. "
            f"Found a maximum value of {arr_max.max()}"
        )

    if arr.min() < 0:
        raise ValueError(
            "Input array must be in the range [0, 1]. "
            f"Found a minimum value of {arr.min()}"
        )

    ipos = arr_max > 0
    delta = np.ptp(arr, -1)
    s = np.zeros_like(delta)
    s[ipos] = delta[ipos] / arr_max[ipos]
    ipos = delta > 0
    # red is max
    idx = (arr[..., 0] == arr_max) & ipos
    out[idx, 0] = (arr[idx, 1] - arr[idx, 2]) / delta[idx]
    # green is max
    idx = (arr[..., 1] == arr_max) & ipos
    out[idx, 0] = 2. + (arr[idx, 2] - arr[idx, 0]) / delta[idx]
    # blue is max
    idx = (arr[..., 2] == arr_max) & ipos
    out[idx, 0] = 4. + (arr[idx, 0] - arr[idx, 1]) / delta[idx]

View on GitHub (pinned to b379c1b69e)

When it happens

Trigger: Thrown at lib/matplotlib/colors.py:3685 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of matplotlib/matplotlib@b379c1b69e (2026-08-21). Data as JSON: /api/errors/08eba18907087e4d. Report an issue: GitHub.