我试图编写一个函数来生成旭日图,但该图显示了一个空白页。没有错误消息。然后我用简单的示例数据进行测试(见下文),但它仍然是空白。当我使用plotly.express 而不是plotly.graph_objects 时,它就可以工作。有人知道为什么吗?感谢您的帮助!
import pandas as pd
import plotly.graph_objects as go
# Sample data
data = {
'Category': ['A', 'A', 'B', 'B'],
'Subcategory': ['A1', 'A2', 'B1', 'B2'],
'Value': [10, 20, 30, 40]
}
df = pd.DataFrame(data)
# Create a basic sunburst chart
fig = go.Figure(go.Sunburst(
labels=df['Subcategory'],
parents=df['Category'],
values=df['Value']
))
fig.update_layout(margin=dict(t=0, l=0, r=0, b=0))
# Save the chart to an HTML file
fig.write_html('basic_hierarchical_sunburst_chart.html')