Black Lives Matter. Please consider donating to Black Girls Code today.

Choropleth map is generated but, not plotting data

I am trying to make a choropleth map that has a slider so that it I can look at different years. The map, slider, and side bar for the values appear but, there is not color on the map. Also when I use the slider the side bar values disappear. Here is my code.

df_summed = df_pre_2003.groupby(['StateName']) ['nAllNeonic'].sum().reset_index()
yrs=['1992', '1993', '1994','1995','1996',
         '1997', '1998', '1999', '2000', '2001','2002','2003']
data = dict(type = 'choropleth', 
           locations = df_summed.StateName,
           locationmode = 'USA-states',
           z = df_summed.nAllNeonic, 
           text = df_summed.StateName,
           colorbar = {'title':'Neonics'},
            )
steps = []
year = 0
for i in range (0,len(data)):
    step = dict(method = "restyle",
                args = ["visible", [False]*len(data)],
                label = yrs[year]) 
    step['args'][1][i] = True
    steps.append(step)
    year += 2

sliders = [dict(active = 10,
                currentvalue = {"prefix": "Year: "},
                pad = {"t": 50},
                steps = steps)]
layout = dict(title = 'Neonic Usage 2003 and before', 
             geo = dict(showframe = False, 
                       projection = {'type': 'albers usa'}),
             sliders=sliders)
#fig = dict(data=data, layout=layout)
#iplot(fig)
choromap3 = go.Figure(data = [data], layout=layout)
iplot(choromap3)

The output is:
Screenshot%20(84)

Here is what I am talking about when the side values disappear.
Screenshot%20(85)

Hi @iiWylde,

I don’t know if this is the whole problem, but it looks like you’re creating a single trace (data) but your steps list seems to assume that you have one trace per year (based on how you set the "visible" arg).

Can you successfully create a choropleth for a single year, without the slider?

-Jon

Unfortunately I can not. I’ve tried a few things and it just gives me a blank map.
The code for one map is:
df_summed = df_pre_2003.groupby([‘StateName’]) [‘nAllNeonic’].sum().reset_index()

> data = dict(type = 'choropleth', 
>            locations = df_summed.StateName,
>            locationmode = 'USA-states',
>            z = df_summed.nAllNeonic, 
>            #text = df_summed.StateName,
>            colorbar = {'title':'Neonics'},
>            )
> layout = dict(title = 'Neonic Usage 2003 and before', 
>              geo = dict(showframe = False, 
>                        projection = {'type': 'albers usa'}))
> #fig = dict(data=data, layout=layout)
> #iplot(fig)
> choromap3 = go.Figure(data = [data], layout=layout)
> iplot(choromap3)

Which just provides a blank map with the data scale on the side (first image in post.)
Here is what I am working with for the data.

Hi @iiWylde,

Could you make your code example self-contained by adding imports and a variable declaration for df_summed that includes some of the relevant data (you don’t need to type in the whole series, just include enough states for people to get a feel for what it should look like)? It will be much easier for folks to try to help you if they can copy and paste your code and start off seeing the same behavior you’re seeing.

Thanks!
-Jon