1

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()

enter image description here

enter image description here

I want to plot a graph like the second one, how should I modify my code and get the plot. Thank you.

1
  • I think there is a typo in your table. Do you want the dates for CMC to increase as well? Commented Aug 7, 2020 at 8:23

1 Answer 1

2

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()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.