diff --git a/supervision/draw/color.py b/supervision/draw/color.py index f3c1474a..8e99ac6c 100644 --- a/supervision/draw/color.py +++ b/supervision/draw/color.py @@ -352,11 +352,15 @@ class ColorPalette: supervision-annotator-examples/visualized_color_palette.png) """ # noqa: E501 // docs mpl_palette = plt.get_cmap(palette_name, color_count) - colors = [ - Color(int(r * 255), int(g * 255), int(b * 255)) - for r, g, b, _ in mpl_palette.colors - ] - return cls(colors) + + if hasattr(mpl_palette, "colors"): + colors = mpl_palette.colors + else: + colors = [mpl_palette(i / (color_count - 1)) for i in range(color_count)] + + return cls( + [Color(int(r * 255), int(g * 255), int(b * 255)) for r, g, b, _ in colors] + ) def by_idx(self, idx: int) -> Color: """