plotly / plotly/plotly.py

plotly.graph_objects.sankey.node.Line does not work with an array of color

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

还没有人认领这个 Issue。

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

描述

Hi everyone,
The docs says that the argument color either takes a color or an array of colors. However, when I pass an array of colors, it always shows up black instead of the specified color. Here is a code example that does the bug :

import plotly.graph_objects as go

# define the node labels and colors
node_labels = ["A", "B", "C", "D"]
node_colors = ["red", "blue", "green", "purple"]

#Array of colors for the node's line
node_line_colors = ["black", "gray", "orange", "yellow"]

# define the links between the nodes
link_source = [0, 0, 1, 1, 2, 2]
link_target = [1, 2, 2, 3, 0, 3]
link_value = [8, 4, 2, 6, 10, 12]

# create the Sankey diagram
fig = go.Figure(data=[go.Sankey(
    node=dict(
        label=node_labels,
        color=node_colors,
        line=dict(
            color=node_line_colors, # Colors I want to have for my diagram
            width=10 # Bigger to properly see that the colors aren't here
        )
    ),
    link=dict(
        source=link_source,
        target=link_target,
        value=link_value
    )
)])

fig.show()

I also tried to manually add the colors like this instead of using the constructor :
fig.data[0]['node']['line']['color'] = node_line_colors

But the node's lines still show up black instead of coloried.
Expected result :
black line for A node,
gray line for B node,
green line for C node,
purple line for D node ;

Actual result :
image

Thanks,

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先运行提供的 go.Sankey 示例,并将文档所述的数组行为与渲染出的节点线进行比较。跟踪 node.line.color 传递给 Sankey 构造函数时的处理方式,然后验证预期的四种颜色是否渲染在相应的节点上。

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

评估

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

把新 issue 发到你的邮箱

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