如何使用 plotly 自定义平行类别图颜色? Python版
How to customize parallel categories diagram colors with plotly ? Python edition
我正在尝试从 Plotly 执行全彩色自定义平行类别图,但我做不到。关于该主题的文档完全是空的:https://plotly.github.io/plotly.py-docs/generated/plotly.graph_objects.parcats.line.colorbar.html 我没有找到示例。
I currently have this
And this is what I want (thank you Paint)
3 列,1 列只有一个类别('Base' 此处),2 列有 2 个类别(此处为“10”和“15”)
提前致谢
根据文档 here 中的示例和 go.Sankey.link?
的输出(如果您在 jupyter 中),您可以检查是否可以使用 [=12] 修改每个 link 的颜色=].
import plotly.graph_objects as go
fig = go.Figure(data=[go.Sankey(
node = dict(
pad = 15,
thickness = 20,
line = dict(color = "black", width = 0.5),
label = ["A1", "A2", "B1", "B2", "C1", "C2"],
color = "blue"
),
link = dict(
source = [0, 1, 0, 2, 3, 3], # indices correspond to labels, eg A1, A2, A2, B1, ...
target = [2, 3, 3, 4, 4, 5],
value = [8, 4, 2, 8, 4, 2],
color = ["red", "green", "orange", "red", "yellow", "green"]
))])
fig.show()
我正在尝试从 Plotly 执行全彩色自定义平行类别图,但我做不到。关于该主题的文档完全是空的:https://plotly.github.io/plotly.py-docs/generated/plotly.graph_objects.parcats.line.colorbar.html 我没有找到示例。
I currently have this
And this is what I want (thank you Paint)
3 列,1 列只有一个类别('Base' 此处),2 列有 2 个类别(此处为“10”和“15”)
提前致谢
根据文档 here 中的示例和 go.Sankey.link?
的输出(如果您在 jupyter 中),您可以检查是否可以使用 [=12] 修改每个 link 的颜色=].
import plotly.graph_objects as go
fig = go.Figure(data=[go.Sankey(
node = dict(
pad = 15,
thickness = 20,
line = dict(color = "black", width = 0.5),
label = ["A1", "A2", "B1", "B2", "C1", "C2"],
color = "blue"
),
link = dict(
source = [0, 1, 0, 2, 3, 3], # indices correspond to labels, eg A1, A2, A2, B1, ...
target = [2, 3, 3, 4, 4, 5],
value = [8, 4, 2, 8, 4, 2],
color = ["red", "green", "orange", "red", "yellow", "green"]
))])
fig.show()