-1

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

rok
  • 15
  • 3
  • 1
    Have you read the Plotly documentation? – alec_djinn Aug 25 '22 at 13:43
  • Does this answer your question? [How to plot multiple lines on the same y-axis using Plotly Express in Python](https://stackoverflow.com/questions/58142058/how-to-plot-multiple-lines-on-the-same-y-axis-using-plotly-express-in-python) – Yevhen Kuzmovych Aug 25 '22 at 13:46
  • Also, you should share your dataframe, or a dummy version of it. https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – alec_djinn Aug 25 '22 at 13:49
  • I added my dataframe – rok Aug 25 '22 at 13:56

1 Answers1

1

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()
alec_djinn
  • 10,104
  • 8
  • 46
  • 71