繁体   English   中英

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

[英]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()

对于sunbursttreemap的新path关键字参数,您必须升级到plotly版本 4.5.0 :)

使用这些命令,它将运行

pip install --upgrade plotly!pip install --upgrade plotly

!pip install --upgrade plotly

它工作正常。 这是由于版本不兼容。

完成此操作后,如果您使用内部代码编辑器,则必须重新启动内核..

但是,如果您使用GOOGLE COLLAB 之类的在线编辑器或其他任何工具,您只需刷新浏览器即可

#更新

如果你还有什么问题,试试这个特定的版本,不要卡在上面。
!pip install plotly==4.8.2

这是更好理解的代码...

fig = px.sunburst(df1,
                  path =['CourseP','CourseS', 'Gender'],
                  title = "Complete overview of students with their course and year of college")
fig.show(renderer="colab")

我在虚拟环境中的 Mac 上运行 Jupyter Notebook 时遇到了同样的问题。 即使在终端内将 plotly 版本升级到 5.9.0 之后:

(plotly_env) $ pip3 freeze | grep plotly
plotly==5.9.0
plotly-express==0.4.1

plotly.__version__仍在笔记本中显示4.4.1 检查环境中已安装包目录的库,升级包在那里:

(plotly_env) $ ls lib/python3.8/site-packages/ | grep '^plotly'
plotly/
plotly-5.9.0.dist-info/
plotly_express/
plotly_express-0.4.1.dist-info/

我终于看到了这篇文章,并使用以下魔法选项在笔记本中升级:

%pip install plotly --upgrade

然后我就可以使用最新的库了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM