Does it change anything if you set autocolorscale=False? You generally don’t want to specify a colorscale ('Viridis' in this case) and set autocolorscale to True.
I can recreate the plot you linked to but for some reason its still not working on my dataset, which you can find here. I checked syntax, data types, null values, etc, but can’t find where the issue is coming from. Thanks in advance for your help!
Thanks for providing the dataset. I’m not sure why plotly.js is responding this way, but the problem seems to be that this DataFrame has two rows for each state (one for each sex) and plotly.js doesn’t know how to handle multiple observations per state.
So you’ll want to do some kind of aggregation in pandas before building the choropleth trace. Here’s a full example of computing the sum of veterans per state (across all values of the sex column). Also, I needed to remove autocolorscale=True in order for the Viridis scale to show up.
import plotly.graph_objs as go
import pandas as pd
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()
state_by_sex = pd.read_csv('https://raw.githubusercontent.com/keryums/projects/master/state_by_sex_wide_20190117_1620.csv')
state_veterans = state_by_sex.groupby('state_code', as_index=False).sum()
data = [ dict(type='choropleth',
colorscale = 'Viridis',
locations=state_veterans.state_code,
z=state_veterans.veterans,
locationmode='USA-states'
)
]
layout = dict(title = 'Map of Veteran Population by State',
geo = dict(scope='usa',
projection=dict(type ='albers usa'),
showlakes = True,
lakecolor = 'rgb(255,255,255)')
)
fig = go.Figure(data=data, layout=layout)
iplot(fig)