Skip to content

px: facet_row_spacing=0 / facet_col_spacing=0 are ignored #5880

Open

Description

@rishi02102017

Passing facet_row_spacing=0 or facet_col_spacing=0 to a Plotly Express function has no effect: the default gap (0.03 / 0.07 between rows, 0.02 between columns) is used instead. The docstring allows any float between 0 and 1, and make_subplots(horizontal_spacing=0, vertical_spacing=0) works fine.

import plotly.express as px

df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", facet_col="smoker", facet_col_spacing=0)
print(fig.layout.xaxis2.domain[0] - fig.layout.xaxis.domain[1])  # 0.02, expected 0

Same with px.imshow(..., facet_col=..., facet_col_spacing=0). Seen on 7.1.0 and current main. The cause is args.get("facet_row_spacing") or 0.07 (and the same pattern for the other defaults) in init_figure, which treats 0 as unset. I have a fix ready.

Disclosure: I found and investigated this with help from an AI assistant (Claude).

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions