Skip to content

When calling update_layout() on a figure, xaxis_range does not update correctly when margin_b is specified #5106

Open
@goldrik

Description

@goldrik
plotly                    6.0.1

I create a figure like so

fig = go.Figure()
fig.add_trace(go.Scatter(x=np.arange(100), y=np.arange(100)))
fig.update_layout(xaxis_range=[50,None])
# fig.update_layout(margin_b=20)
fig.show()

Expected behavior
fig.update_layout(xaxis_range=[50,None]) (Line 3) should set the min xaxis value to be 50, while keeping the max value intact. It does this correctly (Correct: x-axis is from 50 to 100). Interestingly, when I click the modebar to download the plot as png, the xaxis range is incorrect in the output image.

Image

Bug
If you uncomment the line fig.update_layout(margin_b=20) (Line 4) which adjusts the bottom margin, the x axis range is back to its original value unaffected by Line 3 (Inorrect: x-axis is from 0 to 100). Interestingly, if you double click the plot to reset the axes, the x axis changes to the updated value (50 to 100).

Image

Note:
Weirdly, if I change Line 3 to fig.update_layout(xaxis_range=[50,100]) (specify 100 instead of None) and keep the margin_b line uncommented, the behavior is correct again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1needed for current cyclebugsomething brokenregressionthis used to work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions