Plotly Cloropleth Map has Holes in Certain States

Viewed 96

I am looking to plot a map of state, value pairings using the cloropleth function in plotly.express library and for some reason I am seeing holes in the maps. enter image description here

As you can see, there is a hole in Florida and in Utah, and I can't figure out how to remove them. My code is as follows where state is just the two letter code for a state:

import plotly.express as px
fig = px.choropleth(df,
                    locations='state', 
                    locationmode="USA-states", 
                    scope="usa",
                    color='value',
                    color_continuous_scale="darkmint", 
                    title='Map'
                    )

There are no missing values in my data so this is an issue with plotly. Thanks.

2 Answers

Those holes aren't going anywhere since they are in fact The Great Salt Lake in Utah and Lake Okeechobe. in Florida. But you can ignore them in your map with:

fig.update_layout(geo = dict(showlakes=False))

Plot

enter image description here

Complete code:

import plotly.express as px

fig = px.choropleth(locations=["CA", "TX", "NY"], locationmode="USA-states", color=[1,2,3], scope="usa")
fig.update_layout(geo = dict(showlakes=False))
fig.show()

The holes are the Great Salt Lake in Utah and Lake Okeechobee in Florida. It appears these are built into the plotly choropleth graphics you are using.

One way to fix this would be to use something like altair for plotting the choropleth and load in a map that you like.

Edit: See vestland's answer for the right solution (apparently it is possible to ask plotly to ignore the lakes!)

Related