Change the background colour and/or theme

Hello,

I have this app that plot different data based on what you select.

I do not like the background of the default plot as shown below:

I want to get a plot with a white background, dark or gray gridlines and outside border as shown below:
line chart2

I have tried using the theme plotly-white but the border doesn’t show as shown below:
Capture

I even tried using update layout with the code below to change the background to white but it gave something like the following image:

     dcc.Graph(
                            figure=px.bar(
                                df, x="sepal_width", y="sepal_length", color="species"
                            ).update_layout(
                                template='plotly_dark',
                                plot_bgcolor='rgba(0, 0, 0, 0)',
                                paper_bgcolor='rgba(0, 0, 0, 0)',
                            ),
                           
                        )

Resulting to this:

How do I achieve what I want please?
Any help will be appreciated

1 Like

Hi @trinityimma !

You can style the plot gridlines like this:

df = px.data.iris()
fig = px.bar(df, x="sepal_width", y="sepal_length", color="species")
fig.update_layout(
    plot_bgcolor='white'
)
fig.update_xaxes(
    mirror=True,
    ticks='outside',
    showline=True,
    linecolor='black',
    gridcolor='lightgrey'
)
fig.update_yaxes(
    mirror=True,
    ticks='outside',
    showline=True,
    linecolor='black',
    gridcolor='lightgrey'
)

You have more information about this process in this link: Axes in Python

2 Likes

@celia Thank you so much
It works as expected

1 Like