Mixed subplots not working

Hello,

I have a mixed subplot with 2 rows. The first row has 1 column and the second row 2 columns. I used this code from Plotly and adapted it to my needs with this important change:

specs=[[{"type": "yx"}, None],
           [{"type": "xy"}, {"type": "xy"}]])

This throws me an error:

The 'specs' argument to make_subplots must be a 2D list of dictionaries with dimensions (2 x 1).
    Received value of type <class 'list'>: [[{'type': 'yx'}, None], [{'type': 'xy'}, {'type': 'xy'}]]

When I change it to 2 rows and 1 column it works fine. Any idea why it is not working?

Hi @Gobrel ,

maybe it’s the typo {"type": "yx"} instead of {"type": "xy"}?

Otherwise I can’t reproduce your error:

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

# Initialize figure with subplots
fig = make_subplots(
    rows=2, 
    cols=2,
    column_widths=[0.5, 0.5],
    row_heights=[0.5, 0.5],
    specs=[
        [{"type": "xy"}, None],
        [{"type": "bar"}, {"type": "xy"}]
    ]
)

# first trace
fig.add_trace(
    go.Scatter(
        x=np.random.randint(1, 20, 20),
        y=np.random.randint(1, 20, 20),
        mode='markers',
        marker={'color': 'red'},
        showlegend=False
    ),
    row=1, col=1
)

# second trace
fig.add_trace(
    go.Bar(
        y=np.random.randint(1, 20, 20),
        marker={'color': 'green'},        
        showlegend=False,
    ),
    row=2, col=1
)

# third trace
fig.add_trace(
    go.Scatter(
        x=np.random.randint(1, 20, 20),
        y=np.random.randint(1, 20, 20),
        mode='markers',
        marker={'color': 'blue'},
        showlegend=False
    ),
    row=2, col=2
)
fig.update_layout(height=400,width=800)
fig.show()

creates:

1 Like

Thank you, I looked for 1h at my code and didn’t see it.

1 Like