Hi,
Welcome to the community, Chris!
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!