首页 > 解决方案 > Plotly Sunburst - TypeError: sunburst() got an unexpected keyword argument 'path'

问题描述

我试图让 Plotly 的示例代码在 jupyter 笔记本中工作,用于他们网站上的“缺少值的矩形数据”用例。将代码从他们的站点逐字复制到 jupyter 笔记本中,我得到以下 TypeError,有什么想法吗?

TypeError: sunburst() got an unexpected keyword argument 'path'

代码:

import plotly.express as px
import pandas as pd
vendors = ["A", "B", "C", "D", None, "E", "F", "G", "H", None]
sectors = ["Tech", "Tech", "Finance", "Finance", "Other",
           "Tech", "Tech", "Finance", "Finance", "Other"]
regions = ["North", "North", "North", "North", "North",
           "South", "South", "South", "South", "South"]
sales = [1, 3, 2, 4, 1, 2, 2, 1, 4, 1]
df = pd.DataFrame(
    dict(vendors=vendors, sectors=sectors, regions=regions, sales=sales)
)
print(df)
fig = px.sunburst(df, path=['regions', 'sectors', 'vendors'], values='sales')
fig.show()

标签: pythonplotlyvisualization

解决方案


您必须升级到plotly版本 4.5.0 才能获得新的path关键字参数sunbursttreemap:)


推荐阅读