Reputation: 121
I have a dataset like below and they are records of daily admission of different institution
Institution | date | daily_adm|
+------------------+----------+---------------+
| AHN|2020-01-01| 301|
| CMC|2020-01-01| 327|
| AHN|2020-01-02| 251|
| CMC|2020-01-01| 233|
| AHN|2020-01-03| 281|
| CMC|2020-01-01| 292|
| AHN|2020-01-04| 231|
I want to use plotly to plot different institutions' daily admission in everyday in a same plot
But my code below will combine all daily record together and plot a range in everyday, how could I plot each institution separately.
import plotly.express as px
fig = px.line(df, x='date', y='daily_admission')
fig.add_scatter(x=df['date'], y=df['daily_admission'], mode='lines')
fig.show()
I want to plot a graph like the second one, how should I modify my code and get the plot. Thank you.
Upvotes: 1
Views: 120
Reputation: 35230
If you want to distinguish a color by species, specify with the color='Institution'
. The red line of the graph is vertical because the sample data is of '2020-0-01' only.
import plotly.express as px
fig = px.line(df, x='date', y='daily_admission', color='Institution')
# fig.add_scatter(x=df['date'], y=df['daily_admission'], mode='lines')
fig.show()
Upvotes: 2