Search code examples
pythonplotlysubplot

In plotly, how can I create a subplot figure with different numbers of subplots per row?


I'd like to create a plotly figure that has 1 large subplot in the first row and 2 side-by-side subplots in the 2nd row. plotly.subplots.make_subplots forces me to create a rectangular grid, so I'd have to do a 2x2 grid or a 2x1 grid, which isn't what I'm looking for. Is there a way to do this in plotly?


Solution

  • A more complete example is under https://plotly.com/python/subplots/#multiple-custom-sized-subplots. Define the number of rows and columns as the largest number to be able to divide your sections over in the right ratios. Technically you could specify e.g. 35 columns if you want to have one row with 5 columns and another row with 7 columns. The width of each cell can then be specified by "colspan" and similarly "rowspan".

    fig = make_subplots(
    rows=5, cols=2,
    specs=[[{}, {"rowspan": 2}],
           [{}, None],
           [{"rowspan": 2, "colspan": 2}, None],
           [None, None],
           [{}, {}]],
    print_grid=True)