Hi! @trinityimma is right, to make subplots you need to pass the traces, not the whole figure. However, you can access the traces of a figure created with plotly express by iterating over the fig1.data property. It works both for plots with one trace (fig2 in my example) or with three traces (one per color, as in fig1).
Could you try this in your case?
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import plotly.express as px
df = px.data.iris()
fig1 = px.scatter(df, x="sepal_width", y="sepal_length", color='species')
fig2 = px.scatter(df, x="sepal_width", y="petal_width")
fig = make_subplots(
rows=2, cols=1,
shared_xaxes=True,
vertical_spacing=0.02
)
# add each trace (or traces) to its specific subplot
for i in fig1.data :
fig.add_trace(i, row=1, col=1)
for i in fig2.data :
fig.add_trace(i, row=2, col=1)
fig.show()