Skip to content

Plotly Express template margin issue #1689

@fullpwemium

Description

@fullpwemium

Hello,

If I use px for a scatter plot with margin right and bottom set to 0, I get some strange margin on the right anyway

fig = px.scatter(data, x='x', y='y')
fig.update(layout = go.Layout(margin=dict(t=0,r=0,b=40,l=40)))

The same works fine using

fig = go.Figure()

If I try to set a default layout

import plotly.io as pio          # to set mine plot layout
pio.templates['mine'] = pio.to_templated(go.Figure().update_layout(plot_bgcolor='rgba(200,200,200,1)',legend=dict(orientation="h",y=1.1, x=.5, xanchor='center'),margin=dict(t=0,r=0,b=40,l=40))).layout.template
pio.templates.default = 'mine'

It works fine for

fig = go.Figure()

but for

fig = px.scatter(data, x='x', y='y')
fig.show()

I get large padding on top, and the same weird little bit on the right.

I refer to the margin on the right as weird because when I do

fig.layout

I only se

'margin': {'t': 60},

Even if I do

fig.update(layout = go.Layout(margin=dict(t=0,r=0,b=40,l=40)))

afterwards, I still have the weird right margin. No the same issue with go.Figure()

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