Mode='lines+markers' leaves only markers. Why are the lines invisible

basically the top half of the code leaves the following:
Year 15 non-null int64
Payroll_Number 15 non-null int64
Timecode 15 non-null category
Hours_Per_Code 15 non-null float32

@app.callback(Output(component_id=‘graph’, component_property=‘figure’),
[Input(‘year-picker’,‘value’),
Input(‘time-code-picker’,‘value’)])
def update_figure(year_selected, time_code_selected):
filtered_df = df[df[‘Year’]==year_selected]
filtered_df= filtered_df[filtered_df[‘Timecode’]==time_code_selected]
filtered_df = filtered_df.copy(deep=True)
filtered_df = filtered_df.reset_index(drop=True)

traces = []
          
for p in filtered_df['Payroll_Number'].unique():
    df_by=filtered_df[filtered_df['Payroll_Number']==p]

    traces.append(go.Scatter(
        x = df_by['Payroll_Number'],
        y = df_by['Hours_Per_Code'],
        mode='lines+markers',

opacity = 0.9,

        line = dict(color='black', dash='dot', width=1),

name = str(payroll_num)

    ))
          
return {'data': traces,
        'layout': go.Layout(title='Hours',
                            xaxis={'title':'Number'},
                            yaxis={'title':'Hours Per Code', 'tickformat':'.0f'})}

app

I have this code in a Jupyter notebook. Markers works just fine. Lines are invisible. What am I doing wrong? I can’t for the life of me figure this out. I tried sorting the numbers from 1-15. I’m at a loss…The drop downs work, the markers work, but no lines show.
Using Chrome

Thank you for your help!

I could be because you only add one (x,y) for each traces.append…
-> it has to be a list of more elements before the line is created between marks…

maybe try to print out df_by[‘Payroll_Number’] and df_by[‘Hours_Per_Code’] before adding to traces, to see how many elements there are in the list?

1 Like

Hello and thank you so much for taking time to reply!!

Year Payroll_Number Timecode Hours_Per_Code
2019 1 1 188980.78
2019 2 1 200457.66
2019 3 1 206751.16
2019 4 1 220556.44
2019 5 1 218870.84
2019 6 1 220961.1
2019 7 1 222664.42
2019 8 1 221317.38
2019 9 1 198680.55
2019 10 1 217776.5
2019 11 1 212558.33
2019 12 1 201773.42
2019 13 1 213762.48
2019 14 1 196760.2
2019 15 1 212093.66

This is the output right before the loop populates the traces.

Ahhhhhhh yessssssssssssss you were correct!!! thank you so much. I need to past in a list, not loop through the df

1 Like