Skip to content

Bar plot has bad additive color algebra when opacity<1 #4416

Open
@mcstarioni

Description

@mcstarioni

I need to plot a few histograms and for aethetical reasons i prefer to make them semi-transparent and in overlay mode. I have a problem with how plotly handles color additions. I am aware that there is an additive color scheme and subtractive color scheme. I am not sure what scheme in used when plotly combines semi-transparent colors, but the result is absolutely unsatisfactory.
What i expected:
Given 2 original colors "#FD3216", "#00FE35". Mix them in 3'd color like in this site, then display it with given opacity. I expect it to be "#7e9825", but with opacity. Same for dark and light modes.
What i got:
In dark - "#37BD2B", in light "#4DD341". In dark mode the color is almost indestinguishable from one of parent colors, for almost any color sequence.

Here is the code to reproduce the issue:

import torch
from plotly import graph_objects as go, colors

clr_seq = iter(colors.qualitative.Light24)
N_bins = 20
distributions = {'A': torch.normal(0, 1, [1000]),
                 'B': torch.normal(1, 2, [1000]),}
fig = go.Figure()
for k, v in distributions.items():
    fig.add_bar(
        **dict(zip('yx', torch.histogram(
            v, N_bins, range=[-5, 5]))),
        name=k, marker_opacity=0.7, marker_color=next(clr_seq))
fig.update_layout(barmode='overlay', template='plotly_white')
fig.show()

image
image
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions