show geometries for both categorical and numerical fields in the same plot - px.choropleth
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 18.8k
- Forks
- 2.8k
- Avg merge
- 16h 26m
- Merged PRs (30d)
- 21
Description
I am trying to create a US county map (including AK and HI in the bottom corner of the continental map) in plotly. I do not have numerical data for every county. In fact I only have data for 50 counties (approx). I want the map to contain the geometry for the for the counties with not data, so I can plot them in a different color. Otherwise the map is to empty. I tried with add.trace but I could not make it work.
``
import plotly.graph_objs as go
import plotly.express as px
import pandas as pd
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)
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
dtype={"fips": str})
df_nodata=df.loc[df.unemp <= 10]
df_nodata['categorical'] = 'no data'
df_data = df.loc[df.unemp > 10]
fig = px.choropleth(df_data,
geojson=counties,
locations=df_data.fips,
color=df_data.unemp,
scope='usa')
fig.add_trace(go.Figure(go.Choroplethmapbox(geojson=counties, locations=df_nodata.fips, z=df_nodata.categorical))
)
fig.show()
``
I am trying to combine the attached


layers.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example with px.choropleth and the attempted go.Choroplethmapbox trace, then inspect how these entry points compose geographic layers. The result should display counties with data and counties without data in the same US map, with the no-data counties using a distinct color.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100