Skip to content

Missing clipping in n_colors #4105

Closed
@tschuelia

Description

@tschuelia

Hello!

I'm using the n_colors function to generate a list of colors in RGB space and I got the following error message trying to use the generated colors in a plot:
Received value: 'rgb(-2.842170943040401e-14, 255.00000000000003, 0.0)'

Looking at the code for n_colors, I noticed that the computed float values are used directly, however there should be a clipping applied to make sure the values are between 0 and 255.

You should be able to reproduce this issue like this:

from plotly.colors import n_colors
n_colors(lowcolor="rgb(255,0,0)", highcolor="rgb(0,255,0)", n_colors=14, colortype="rgb")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions