I want to keep the figures in the exact same way, for example, having different data source, subplot title and respective legends near EACH figure.
currently the code is sth. like
fig1 = px.line(df_crude_spot_long, x="Date", y="$/bbl", color='type', title='Benchmark Crude Spot Prices', color_discrete_sequence=px.colors.qualitative.Bold)
fig1.update_layout(
xaxis_title="",
title={
# 'text': "Plot Title",
# 'y':0.9,
'x':0.5},
legend_title="Benchmark",
font=dict(
family="Courier New, monospace",
size=40,
color="navy"),
legend=dict(
yanchor="top",
y=0.99,
xanchor="left",
x=0.01
)
)
fig2 = px.line(df_crude_futures, x="contract month", y='Price', color='futures', title='Latest Crude Oil Futures', color_discrete_sequence=px.colors.qualitative.Bold)
fig2.update_layout(
title={
# 'text': "Plot Title",
# 'y':0.9,
'x':0.5},
legend_title="Futures",
font=dict(
family="Courier New, monospace",
size=40,
color="navy"),
legend=dict(
yanchor="top",
y=0.99,
xanchor="left",
x=0.8
)
)
fig3
fig4
....
As you can see, the data source for different figures are not from the same dataframe.
I tried the 2nd approach in this post, by combining make_subplots and plotly express with code like this
Is it possible to create a subplot with Plotly Express?
fig = make_subplots(
rows=2, cols=2,
subplot_titles=("BenchmarkPrices", "Latest Oil Futures", "Bunker Prices", "Fuel Futures"))
for d in fig1.data:
fig.add_trace((go.Scatter(x=d['x'], y=d['y'], name = d['name'])), row=1, col=1)
for d in fig2.data:
fig.add_trace((go.Scatter(x=d['x'], y=d['y'], name = d['name'])), row=2, col=1)
for d in fig3.data:
fig.add_trace((go.Scatter(x=d['x'], y=d['y'], name = d['name'])), row=2, col=1)
for d in fig4.data:
fig.add_trace((go.Scatter(x=d['x'], y=d['y'], name = d['name'])), row=2, col=2)
but the result has some of the figures not shown properly and all the legends put together on the right side.
I mentioned Html file in the title because I generally save my figure like below
offline.plot({'data':fig},filename='charts.html',auto_open=False)
Update 1 The comment section suggested the method in this post Plotly saving multiple plots into a single html
it puts several figures under 1 html but doesn't solve my problem because 1.I need to produce a 2 x 4 charts(2 charts per row and 4 rows in total), with this way it only put 1 chart per row. 2. when I download png from the html, it only shows the 1st figure, even on the html we see the 4