在一张图中绘制多个 pandas 数据帧 python plotly
plot multiple pandas dataframes in one graph python plotly
我想使用 python plotly 在一张图中绘制 多个 pandas 数据框的折线图 (设置 x 轴:Day-shift 和 y 轴:PRO)。
我试过使用 for 循环,但它未能生成预期的结果 output.Code 我试过的如下所示。
import plotly.express as px
for frame in [df1, df2, df3, df4, df5]:
fig = px.line(frame, x='Day-Shift', y='PRO',template="plotly_dark")
fig.show()
另外我想将图例设置为 df1 到 df5
有了plotly你可以尝试以下方法:
import pandas as pd
import plotly.graph_objects as go
from plotly.offline import iplot
# dict for the dataframes and their names
dfs = {"df1" : df1, "df2": df2, "df3" : df3, "df4" : df4, "df5" : df5}
# plot the data
fig = go.Figure()
for i in dfs:
fig = fig.add_trace(go.Scatter(x = dfs[i]["day-shift"],
y = dfs[i]["PRO"],
name = i))
fig.show()
我想使用 python plotly 在一张图中绘制 多个 pandas 数据框的折线图 (设置 x 轴:Day-shift 和 y 轴:PRO)。
我试过使用 for 循环,但它未能生成预期的结果 output.Code 我试过的如下所示。
import plotly.express as px
for frame in [df1, df2, df3, df4, df5]:
fig = px.line(frame, x='Day-Shift', y='PRO',template="plotly_dark")
fig.show()
另外我想将图例设置为 df1 到 df5
有了plotly你可以尝试以下方法:
import pandas as pd
import plotly.graph_objects as go
from plotly.offline import iplot
# dict for the dataframes and their names
dfs = {"df1" : df1, "df2": df2, "df3" : df3, "df4" : df4, "df5" : df5}
# plot the data
fig = go.Figure()
for i in dfs:
fig = fig.add_trace(go.Scatter(x = dfs[i]["day-shift"],
y = dfs[i]["PRO"],
name = i))
fig.show()