gpt4 book ai didi

plotly - bundle 名称 Sankey plotly

转载 作者:行者123 更新时间:2023-12-04 10:08:21 26 4
gpt4 key购买 nike

我想知道如何在 plotly 中将包名称添加到 Sankey 图中。通过捆绑,我理解一列中的节点。从 plotly 教程:

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]
))])

fig.update_layout(title_text="Basic Sankey Diagram", font_size=10)
fig.show()

enter image description here

我想添加的是捆绑标题,如:
enter image description here

我在文档中找不到这个选项,也找不到破解它的方法。

最佳答案

你认为这可以作为一个起点吗?

fig = go.Figure()
fig.add_trace(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]
)))
fig.add_trace(go.Scatter(x=[0,1,2], y=[None]*3))
fig.update_xaxes(side='top')
fig.update_layout(title_text="Basic Sankey Diagram",
title_x=0.5,
font_size=10,
plot_bgcolor='white',
xaxis = dict(showgrid=False,
tickmode = 'array',
tickvals = [0, 1, 2],
ticktext = ["bundle name 1", "bundle name 2", "bundle name 3"]),
yaxis = dict(showgrid=False,
showticklabels=False)

)

fig.show()

enter image description here

我使用的技巧是:
  • 添加一个假散点( yNone )
  • 搬家 xaxes到顶部
  • 将背景颜色更改为 white
  • 摆脱showgrid二轴上
  • xaxis 上添加自定义刻度
  • 删除 yaxis 上的刻度标签
  • 关于plotly - bundle 名称 Sankey plotly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61460424/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com