0
from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig1 = px.area(CPI_and_Interest, x=CPI_and_Interest.index, y=Chi_so)
    
fig2 = px.line(CPI_and_Interest, x=CPI_and_Interest.index, y=[‘Overnight’])
    
fig = make_subplots(rows=2, cols=1,
  shared_xaxes=True,
  vertical_spacing=0.02)
    
fig.add_trace(fig1, row=1, col=1)
fig.add_trace(fig2, row=2, col=1)
    
fig.show()

I have been trying to create a subplot with these 2 above plots (fig1 and fig2). However, it keeps showing me this following error:

All remaining properties are passed to the constructor of the specified trace type

  (e.g. [{'type': 'scatter', ...}, {'type': 'bar, ...}])

Any ideas how to fix this?

Azhar Khan
  • 3,829
  • 11
  • 26
  • 32

1 Answers1

0

You are using plotly.express with add_trace. Instead, use plotly.graph_objects. Like this:

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(rows=1, cols=2)

fig.add_trace(
go.Scatter(x=[1, 2, 3], y=[4, 5, 6]),
row=1, col=1)

fig.add_trace(
go.Scatter(x=[20, 30, 40], y=[50, 60, 70]),
row=1, col=2)


fig.show()

For further clarification, read the documentation: https://plotly.com/python/subplots/

Mujtaba Mateen
  • 202
  • 2
  • 7