镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Certain padding values cause plots to overtake all other subplots #4144

Open

Description

@stephenpardy

Related to #4124 there is a set of padding values that will produce strange behavior such that a single subplot takes over all others.

Some setup:

import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
line_x = np.arange(10)
line_y = line_x**2

What works:

n_subplots = 6

full_fig = make_subplots(
    rows=n_subplots,
    cols=1,
)

for row_idx in range(1, n_subplots+1):
    full_fig.add_trace(go.Scatter(
            x=line_x,
            y=line_y,
            showlegend=False,
        ), row=row_idx, col=1)

This produces 6 different subplots of the same line.

What doesn't work:

line_x = np.arange(10)
line_y = line_x**2

n_subplots = 8
padding_size = 0.1

row_heights = [0.1]*n_subplots

specs = []
for _ in range(n_subplots):
    specs.append([{'b': padding_size/2., 't': padding_size/2.}])

full_fig = make_subplots(
    rows=n_subplots,
    cols=1,
    row_heights=row_heights,
    specs=specs,
)

for row_idx in range(1, n_subplots+1):
    full_fig.add_trace(go.Scatter(
            x=line_x,
            y=line_y,
            showlegend=False,
        ), row=row_idx, col=1)

Adding the padding and row heights now generates only a single plot.

Activity

  1. self-assigned this
    on Jul 11, 2024
  2. removed their assignment
    on Aug 2, 2024
  3. emilykl commented on Sep 1, 2026

    @emilykl
    Contributor

    Hi @stephenpardy, apologies this issue never got a timely response — I just wanted to add a note here that this (bad!) behavior is due to the fact that b and t padding values are interpreted in terms of paper fraction of the entire plot, not as a fraction of the cell itself.

    The explanation which gets a bit in the weeds... make_subplots already adds a default vertical spacing of 0.3 / nrows spacing between each pair of subplots, also in units of plot fraction, which means that each subplot cell takes up (1-0.3/8*7)/8 ≈ 0.0922 of the vertical plot area. (Passing row_heights doesn't bypass the default vertical_spacing). As a result, adding a total of 0.1 units of plot fraction to each subplot exceeds the total of 0.0922 units of plot fraction allowed for the whole subplot, so make_subplots falls back to an unfortunate failure case of just defaulting to [0, 1] vertical domain for every subplot, resulting in the overlap where only the final subplot is visible.

    All that to say, this is a bad API and the most minimal change would be to adjust the spec validation make_subplots() to catch this case, the way it does if you pass a really large value for the margin padding in specs. The whole subplot padding/spacing API should probably be improved as well, but that's a larger chunk of work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions