Learning Dash - How to Add Traces

Hi,

Welcome to the community, Chris! :slightly_smiling_face:

Your code number one can be fixed by changing the first line to:

fig = go.Figure()
fig.add_trace(...) # and so on

I changed data to fig because that’s usually how the object gets initialized (so it can be less confusing for you).

You can add traces to fig using fig,add_traces(), of course. Another approach is to pass the traces in a list on initialization using the data argument:

fig = go.Figure(
     data=[
          go.Scatter(...),
          go.Scatter(...),
          # and whatever traces you need...
     ]
)

I guess this is closer to the method 2 you mentioned.

Link to the docs: Creating And Updating Figures

Hope this helps! :slightly_smiling_face:

3 Likes