Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

How to add ~100 traces in a plot without using an API call each time?

I’m creating a plot with ~100 traces and would like to add them all at once, but right now each one requires a data call. Any ideas? Documentation showed the preferred method for adding traces is:

a loop that looks something like this:
plotData = my data…
trace = go.Scatter(x=date_series,y=plotData[0)
dataPanda = [trace]
layout = dict( … )

fig = dict(data=dataPanda, layout=layout)
py.iplot(fig, filename=‘My Chart’)

if len(plotData) > 0:
    for index, i in enumerate(plotData, start=1):
        trace = go.Scatter(x=date_series,y=i)
        dataPanda = [trace]
        fig = dict(data=dataPanda, layout=layout)
        py.iplot(fig, filename='CurrWYAllActive', fileopt='append')

is there a way the py.iplot can take all the traces at once? I tried simply adding the entire list which populates the data but doesn’t make a chart with any of it…

3 Likes

So if I understand your question properly, you just want to be able to plot a 100-trace chart in one API call.

You can just do something like this:

dataPanda = []
for data in plotData:
    trace = go.Scatter(...)
    dataPanda.append(trace) 

# now do the api call
fig = dict(data=dataPanda, layout=layout)
py.iplot(fig)

You’re just making a list of your traces [trace1, trace2, ..., traceN] and then plotting that

6 Likes