Error choropleth() got an unexpected keyword argument 'geojson'

I am trying to use Plot.ly choropleth map vizualisation, but when I copy the example code (or when I customize it) I get the following error : TypeError: choropleth() got an unexpected keyword argument ‘geojson’

I am running this code

from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)

import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
                   dtype={"fips": str})

import plotly.express as px

fig = px.choropleth(df, geojson=counties, locations='fips', color='unemp',
                           color_continuous_scale="Viridis",
                           range_color=(0, 12),
                           scope="usa",
                           labels={'unemp':'unemployment rate'}
                          )
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

Any ideas why?

Hi @yo.angelina, welcome to the forum! The geojson attribute was introduced in the latest release of plotly.py (4.5), maybe you have an older version installed? You can check it with

import plotly
print(plotly.__version__)

You can update your version of plotly by doing pip install -U plotly (or with conda if you’re using conda). More instructions are given in https://plot.ly/python/getting-started/

1 Like

Hi @Emmanuelle, thanks!

Indeed, it was version problem (I had 4.4.1 installed). Everything works now :slight_smile: