roboflow/supervision · error · ValueError
color_count must be greater than or equal to 1
Error message
color_count must be greater than or equal to 1
What it means
Error "color_count must be greater than or equal to 1" thrown in roboflow/supervision.
Source
Thrown at src/supervision/draw/color.py:513
palette_name: Name of the Matplotlib palette.
color_count: Number of colors to sample from the palette.
Returns:
A ColorPalette instance.
Example:
```pycon
>>> import supervision as sv
>>> sv.ColorPalette.from_matplotlib('viridis', 5) # doctest: +ELLIPSIS
ColorPalette(colors=[Color(r=68, g=1, b=84), Color(r=58, g=82, b=139), ...])
```

"""
if color_count < 1:
raise ValueError("color_count must be greater than or equal to 1")
# Keep pyplot lazy so importing color utilities does not import matplotlib.
import matplotlib.pyplot as plt
mpl_palette = plt.get_cmap(palette_name)
if hasattr(mpl_palette, "resampled"):
mpl_palette = mpl_palette.resampled(color_count)
if hasattr(mpl_palette, "colors"):
colors = mpl_palette.colors
else:
# A single color samples the palette start and avoids division by zero.
positions = (
[0.0]
if color_count == 1
else [i / (color_count - 1) for i in range(color_count)]
)
colors = [mpl_palette(position) for position in positions]View on GitHub (pinned to 7f254d9784)
Solutions
- Request at least one color when generating a palette (color_count >= 1).
- Guard the call so color_count is never zero or negative.
When it happens
Trigger: Thrown at src/supervision/draw/color.py:513 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/b1cfde02f27b7745.
Report an issue: GitHub.