![](/img/trans.png)
[英]Plotly: Plot multiple pandas DataFrames in one graph with conditions
[英]plot multiple pandas dataframes in one graph python plotly
我想使用python plotly (設置 x 軸: Day-shift和 y 軸: PRO )在一個圖中繪制多個熊貓數據框的折線圖。
我嘗試使用 for 循環,但未能生成預期的輸出。我嘗試的代碼如下。
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.