所以我試圖將兩個地塊合二為一。我用 plotly.express 庫而不是 plotly.graphs_objs 繪制了這些圖。現在,plotly 建議使用: fig = make_subplots(rows=3, cols=1)然后append_trace或add_trace
但是,這不適用于 express 物件,因為附加跟蹤需要單個。痕跡。如何將快速圖形添加到子圖中?或者這根本不可能。我嘗試過的一個選項是,fig.data[0]但這只會添加第一行/資料條目。Rn 我的代碼看起來像:
double_plot = make_subplots(rows=2, cols=1, shared_xaxes=True)
histo_phases = phases_distribution(match_file_, range)
fig = px.line(match_file,
x="Minutes", y=["Communicatie", 'Gemiddelde'], color='OPPONENT')
fig.update_layout(
xaxis_title="Minuten",
yaxis_title="Communicatie per " str(range) "minuten",
legend_title='Tegenstander',
)
double_plot.append_trace(fig.data, row=1, col=1)
double_plot.append_trace(histo_phases.data, row=2, col=1)
提前致謝。
uj5u.com熱心網友回復:
- 您的代碼示例不包括資料框和圖形的創建。模擬過
- 它就像將使用plotly express創建的圖形中的每個軌跡添加到使用創建的圖形一樣簡單
make_subplots()
for t in fig.data:
double_plot.append_trace(t, row=1, col=1)
for t in histo_phases.data:
double_plot.append_trace(t, row=2, col=1)
完整代碼
from plotly.subplots import make_subplots
import plotly.express as px
import pandas as pd
import numpy as np
df = px.data.tips()
double_plot = make_subplots(rows=2, cols=1, shared_xaxes=True)
# histo_phases = phases_distribution(match_file_, range)
histo_phases = px.histogram(df, x="total_bill")
match_file = pd.DataFrame(
{
"Minutes": np.repeat(range(60), 10),
"Communicatie": np.random.uniform(1, 3, 600),
"Gemiddelde": np.random.uniform(3, 5, 600),
"OPPONENT": np.tile(list("ABCDEF"), 100),
}
)
fig = px.line(match_file, x="Minutes", y=["Communicatie", "Gemiddelde"], color="OPPONENT")
fig.update_layout(
xaxis_title="Minuten",
yaxis_title="Communicatie per " str(range) "minuten",
legend_title="Tegenstander",
)
for t in fig.data:
double_plot.append_trace(t, row=1, col=1)
for t in histo_phases.data:
double_plot.append_trace(t, row=2, col=1)
double_plot
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/380248.html
上一篇:根據查詢條件從資料庫中檢索資料
