要使用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()
通過按照上述步驟操作,您可以創建并顯示一個交互式的太陽圖,用于可視化層次結構數據。