swk
swk

Reputation: 31

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

i'm trying to get Plotly's sample code working in a jupyter notebook for the 'Rectangular Data With Missing Values' use case on their site. Copying the code from their site verbatim into a jupyter notebook, I get the following TypeError, any ideas?

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

Code:

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()

Upvotes: 2

Views: 4814

Answers (4)

Heelara
Heelara

Reputation: 979

I had the same issue running Jupyter Notebook on my mac within a virtual environment. Even after upgrading plotly version within terminal to 5.9.0:

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

plotly.__version__ was still showing 4.4.1 within notebook. Checking the library of installed packages directory within the environment, the upgraded package was there:

(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/

I finally came across this post, and used the following magic option to upgrade within notebook:

%pip install plotly --upgrade

I was then able to use the latest library.

Upvotes: 0

Raj Chauhan
Raj Chauhan

Reputation: 31

!pip install --upgrade plotly

its working fine. it's due to version incompatibility.

After doing this you must need to Restart kernel if you use an internal Code editor..

But if you use online editor like GOOGLE COLLAB or anything you just Refresh your browser.

#update

If you still have any problems, try this specific version, not stuck on it.
!pip install plotly==4.8.2

this is code for better understanding...

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

Upvotes: 0

Aarti Chauhan
Aarti Chauhan

Reputation: 1

Use these commands and it will run

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

Upvotes: 0

nicolaskruchten
nicolaskruchten

Reputation: 27410

You'll have to upgrade to plotly version 4.5.0 for the new path keyword argument to sunburst and treemap :)

Upvotes: 1

Related Questions