3

I recently started playing around with the plotly.express library for making choropleth maps. I've been able to create one just fine using a GeoJSON of a state's census tracts and a Pandas dataframe, however, I'd like to add another "layer" on top of the census tracts to show where municipal boundaries are (I have a GeoJSON for this as well). I haven't been able to find a walkthrough/guide where someone does something like this, and I haven't been able to figure out much from the plotly documentation.

Here's my code for the main choropleth plot:

fig = px.choropleth(
    df,
    geojson= Tracts,
    locations= df['TRACTCE10'],
    color= df['someVariable'],
    color_discrete_map={"None":'LightGray',
                        "Cat1":'LightGreen',
                        "Cat2":'LightPink',
                        "Cat3":'LightSeaGreen'},
    featureidkey= 'properties.tractce10',
    projection='mercator' 
)

fig.update_geos(fitbounds="locations", visible=True)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show() 

Any advice or links to a possible solution?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.