为类型为 plotly.graph_objs.sankey.链接的对象指定的属性无效:'customdata'



我正在尝试将自定义数据添加到Sankey Chart上的链接和节点中。我指的是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"],
customdata = ["Long name A1", "Long name A2", "Long name B1", "Long name B2",
"Long name C1", "Long name C2"],
hovertemplate='Node %{customdata} has total value %{value}<extra></extra>',
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],
customdata = ["q","r","s","t","u","v"],
hovertemplate='Link from node %{source.customdata}<br />'+
'to node%{target.customdata}<br />has value %{value}'+
'<br />and data %{customdata}<extra></extra>',
))])
fig.update_layout(title_text="Basic Sankey Diagram", font_size=10)
fig.show()

我收到一个错误,根据他们的文档,我们可以使用customdata来显示额外的数据。我不确定他们网站上的文件是否是最新的,或者我是否做错了什么。提前感谢你的帮助。

为plotly.graph_objs.sankey.Link:"customdata"类型的对象指定的属性无效

customdata属性对于Plotly的最新版本(发布此答案时为4.14.3版(的Plotly Sankey Chart graph_object有效,此属性的描述可在最新文档中找到。将plotly更新到最新版本应该可以解决此问题。

最新更新