I am working on a line graph that has a slider control. I am following the tutorial on the website and have come across a problem.
df_summed = df_pre_2003.groupby(['year']) ['nAllNeonic'].sum().reset_index()
traces=[]
q=df_summed
for i in range (0,len(q)):
trace=dict(
type='scatter',
visible = False,
line=dict(color='#00CED1', width=6),
width=0.5,
x = df_summed.year,
y = df_summed.nAllNeonic
)
traces[1129]['visible'] = True
steps=[]
for i in range(len(traces)):
step=dict(
method='restyle',
args=['visible', [False] * len(data)],
)
step['args'][1][i] = True
steps.append(step)
sliders = [dict(
active = 10,
currentvalue = {"prefix": "Year: "},
#pad = {"t": 50},
steps = steps
)]
layout = go.Layout(
width=500,
height=500,
autosize=False,
yaxis=dict(range=[0, 1])
)
layout['sliders'] = sliders
fig = go.Figure(data=traces, layout=layout)
#fig = dict(data=data, layout=layout)
pyo.iplot(fig, show_line=False)
This gives me an error:
IndexError: list index out of range
Specificlly at this line: traces[1129]['visible'] = True
Now I did some messing around like checking the index of df_pre_2003 like so, df_pre_2003.index.values
and recived an array that starts at 0 and goes until 1129.
So I changed traces to what is above and still doesn’t work.
The size of df_pre_2003 is 524 rows by 18 columns and the years are 1998 to 2003
My ultimate goal is to get a line graph with a slider like this Sliders in Python except instead of steps in the example it would be years for mine/ .