要使用Plotly的Sunburst类创建交互式太阳图(sunburst chart),您可以按照以下步骤操作:
import plotly.graph_objects as go
data = {
"label": "Top Level",
"children": [
{
"label": "A",
"parent": "Top Level",
"value": 10
},
{
"label": "B",
"parent": "Top Level",
"children": [
{
"label": "B1",
"parent": "B",
"value": 5
},
{
"label": "B2",
"parent": "B",
"value": 8
}
]
}
]
}
fig = go.Figure(go.Sunburst(
labels=data['labels'],
parents=data['parents'],
values=data['values'],
branchvalues='total',
))
fig.update_layout(
margin=dict(t=0, l=0, r=0, b=0),
title_text='Sunburst Chart',
)
fig.show()
通过按照上述步骤操作,您可以创建并显示一个交互式的太阳图,用于可视化层次结构数据。