简体   繁体   中英

How to plot multiple y-axes by plotly python

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.

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM