Removing the white border around Plotly chart in Python
Asked Answered
S

2

7

How can I remove the white margin/border around the figure?

import pandas as pd
import numpy as np
import plotly.express as px


df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
                   columns=['a', 'b', 'c'])

fig = px.line(df, x=df.index, y=['a', 'b', 'c'], template='plotly_dark')
fig.show()

Tried without the templates, as well as removing margins, padding and backgrounds via

fig.update_layout(
    margin=dict(l=0,r=0,b=0,t=0),
    paper_bgcolor="Black"
    )

Screenshot showing the white border

Saccharine answered 18/8, 2021 at 3:2 Comment(0)
B
4

You already did it! In fact, I was looking for an answer to remove the whitespace borderlines in the plot, and your question taught me how to do that! I appreciate your work! In order to make your code work as you intended, you just need to update your layout before showing your figure(using fig.show()) as follows:

import pandas as pd
import numpy as np
import plotly.express as px


df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
                   columns=['a', 'b', 'c'])

fig = px.line(df, x=df.index, y=['a', 'b', 'c'], template='plotly_dark')
## Put your layout updating here
fig.update_layout(
    margin=dict(l=0,r=0,b=0,t=0),
    paper_bgcolor="Black"
    )

fig.show()
Babe answered 4/2, 2022 at 17:32 Comment(0)
W
0

Please try put this in fig.update_layout

xaxis=dict(visible=False, showgrid=False, showline=False), 
yaxis=dict(visible=False, showgrid=False, showline=False),
Washedup answered 16/12, 2023 at 17:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.