For a single plot without subplots, it’s easy:
fig = px.line(covid, x=covid[‘ObservationDate’], y=covid.columns[2:])
where, covid.columns returns:
Index([‘Country/Region’, ‘ObservationDate’, ‘Confirmed’, ‘Recovered’, ‘Deaths’], dtype=‘object’)
But this is where I get stumped - when I want to do the same with subplots. For example:
fig = make_subplots(rows=3)
fig.add_trace(
go.Line(x=covid_china['ObservationDate'], y=covid_china['Confirmed']),
row=1, col=1
)
fig.add_trace(
go.Line(x=covid_china['ObservationDate'], y=covid_china['Recovered']),
row=1, col=1
)
fig.add_trace(
go.Line(x=covid_china['ObservationDate'], y=covid_china['Deaths']),
row=1, col=1
)
fig.add_trace(
go.Line(x=covid_us['ObservationDate'], y=covid_us['Confirmed']),
row=2, col=1
)
fig.add_trace(
go.Line(x=covid_us['ObservationDate'], y=covid_us['Recovered']),
row=2, col=1
)
fig.add_trace(
go.Line(x=covid_us['ObservationDate'], y=covid_us['Deaths']),
row=2, col=1
)
fig.add_trace(
go.Line(x=covid_india['ObservationDate'], y=covid_india['Confirmed']),
row=3, col=1
)
fig.add_trace(
go.Line(x=covid_india['ObservationDate'], y=covid_india['Recovered']),
row=3, col=1
)
fig.add_trace(
go.Line(x=covid_india['ObservationDate'], y=covid_india['Deaths']),
row=3, col=1
)
fig.update_layout(height=600, width = 800)
fig.show()
I could not pass in multiple sets of y-values to go.Line(); the only way to make it work was as above - calling a .add_trace() for each set of y-values. Help?