简体   繁体   中英

LIne graph using plotly

With this script, it is open 2 dashboards and so 2 graphs How i can modify it to see all on the same graph? dataframe:



    df = pd.DataFrame( df_abs.to_numpy()[:, 1:].T).reset_index().melt(id_vars="index")
    fig = px.line(df, x="index", y="value", color="variable")
    fig.show()

script dot plotly:

df_abs = pd.DataFrame(df_abs.loc[outlier].iloc[1:]).reset_index().melt(id_vars="index")
fig = px.line(df_abs, x="index", y="value", color="variable")
fig.show()

df = pd.DataFrame( df_abs.to_numpy()[:, 1:].T).reset_index().melt(id_vars="index")
fig = px.line(df, x="index", y="value", color="variable")
fig.show()

You need to use plotly.graph_objects instead of plotly.express .

plotly.express is great for quick plots but it is somewhat limited compared to plotly.graph_objects .

Here is a dummy example using 2 dataframes to make it similar to your case.

import plotly.graph_objects as go
import plotly.express as px

df1 = px.data.gapminder().query("country in ['Canada']")
df2 = px.data.gapminder().query("country in ['Italy']")

fig = go.Figure()
fig.add_trace(go.Scatter(x=df1["lifeExp"], y=df1["gdpPercap"], mode='lines', name='Canada'))
fig.add_trace(go.Scatter(x=df2["lifeExp"], y=df1["gdpPercap"], mode='lines', name='Italy'))
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