plotly / plotly/plotly.py

Bar plot has bad additive color algebra when opacity<1

未关闭
#4,416 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P3
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从提供的 Python 复现开始,使用 go.Figure.add_bar、marker_opacity、barmode='overlay' 和 template='plotly_white';比较浅色和深色模式下渲染出的重叠颜色。跟踪从该入口开始的透明度和颜色合成行为,并在重叠的半透明条形图在两种模式下都一致地产生文档中预期的混合结果时,认为 issue 已完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python, pytorch
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。