Choropleth charts are not working


I’m not sure what I’m doing wrong
all choropleth maps are just empty

I just copied the code from

[type or paste code here](https://plotly.com/python/tile-county-choropleth/)

Appreciate any help

My environment

Package                   Version
------------------------- -----------
asttokens                 2.4.1
attrs                     23.2.0
beautifulsoup4            4.12.3
certifi                   2024.6.2
cffi                      1.16.0
charset-normalizer        3.3.2
colorama                  0.4.6
comm                      0.2.2
contourpy                 1.2.1
cycler                    0.12.1
debugpy                   1.8.2
decorator                 5.1.1
et-xmlfile                1.1.0
executing                 2.0.1
fastjsonschema            2.20.0
fonttools                 4.53.0
h11                       0.14.0
html5lib                  1.1
idna                      3.7
ipykernel                 6.29.4
ipython                   8.25.0
jedi                      0.19.1
jsonschema                4.23.0
jsonschema-specifications 2024.10.1
jupyter_client            8.6.2
jupyter_core              5.7.2
kiwisolver                1.4.5
matplotlib                3.9.0
matplotlib-inline         0.1.7
nbformat                  5.10.4
nest-asyncio              1.6.0
numpy                     2.0.0
openpyxl                  3.1.4
outcome                   1.3.0.post0
packaging                 24.1
pandas                    2.2.2
parso                     0.8.4
pillow                    10.3.0
pip                       24.1
platformdirs              4.2.2
plotly                    5.24.1
prompt_toolkit            3.0.47
psutil                    6.0.0
pure-eval                 0.2.2
pycparser                 2.22
Pygments                  2.18.0
pyparsing                 3.1.2
pyperclip                 1.9.0
PySocks                   1.7.1
python-dateutil           2.9.0.post0
pytz                      2024.1
pywin32                   306
pyzmq                     26.0.3
referencing               0.35.1
requests                  2.32.3
rpds-py                   0.20.0
selenium                  4.22.0
setuptools                70.1.1
six                       1.16.0
sniffio                   1.3.1
sortedcontainers          2.4.0
soupsieve                 2.5
stack-data                0.6.3
tenacity                  9.0.0
tornado                   6.4.1
tqdm                      4.66.5
traitlets                 5.14.3
trio                      0.25.1
trio-websocket            0.11.1
typing_extensions         4.12.2
tzdata                    2024.1
undetected-chromedriver   3.5.5
urllib3                   2.2.2
wcwidth                   0.2.13
webencodings              0.5.1
websocket-client          1.8.0
websockets                12.0
wsproto                   1.2.0

Hey @Dzirt07 welcome to the forums.

Would you be so kind posting the code instead of an image of the code? It would make it easier for us to help you.

Sure,

I apologize

from urllib.request import urlopen
import plotly.express as px
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})


fig = px.choropleth_map(df, geojson=counties, locations='fips', color='unemp',
                           color_continuous_scale="Viridis",
                           range_color=(0, 12),
                           map_style="carto-positron",
                           zoom=3, center = {"lat": 37.0902, "lon": -95.7129},
                           opacity=0.5,
                           labels={'unemp':'unemployment rate'}
                          )
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

I did not change anything in the code, here the graph:

Not sure if that is related to jupyterlab. Could you run this in the console?

:thinking:
do you mind to share your list of your packages ?

I’m going to delete my virtual environment and reinstall everything, maybe some other libs are conflicting with each other

plotly: 5.24.1
pandas: 2.2.2

These are the relevant ones. I guess it could be related to jupyter. Try just installing the apove to your venv and check again. Then add jupyter and check

Thanks, you were right
The code doesn’t work in VS code only with Jupiter Extension

thank you

1 Like