AnnMarieW / dash-bootstrap-templates

A collection of 52 Plotly figure templates with a Bootstrap theme. Two theme switch components. Stylesheet to apply Bootstrap themes to Plotly Dash components.
https://hellodash.pythonanywhere.com/
MIT License
135 stars 25 forks source link

Regression bug: Background color of graph no longer transparent #25

Closed TheDurableDane closed 10 months ago

TheDurableDane commented 10 months ago

There seems to be a regression from version 1.0.8 to version 1.1.0. I have created this tiny example to show the difference:

#!/usr/bin/env python
from dash import Dash, html, dcc
import dash_bootstrap_components as dbc
from dash_bootstrap_templates import load_figure_template
import plotly.graph_objects as go

load_figure_template('darkly')

app = Dash(__name__, external_stylesheets=[dbc.themes.DARKLY])

app.layout = html.Div([
    dbc.Card(
        dbc.CardBody(
            dcc.Graph(figure=go.Figure(go.Scatter(x=[1, 2, 3], y=[2, 5, 3]))),
        )
    )
])

if __name__ == '__main__':
    app.run(debug=True, port=8080)

When running on version 1.1.0, it looks like this: image

But prior to this version, e.g. version 1.0.8, it looked like this: image

The difference might seem small, but when you add labels on the axes, titles, etc. the old version looks much better. Do you agree that this is a regression or is it intended behavior? It there an easy fix or workaround?

AnnMarieW commented 10 months ago

Hi @TheDurableDane

Thanks for reporting! That change was not intended. I'll do an update in a few days, but in the meantime, here are a couple workarounds:

You can update the figure template, then all the figures in your app will have the correct background color:

load_figure_template('darkly')
plotly.io.templates["darkly"].layout.paper_bgcolor="#303030"

Or you can update it in each figure:


fig=go.Figure(go.Scatter(x=[1, 2, 3], y=[2, 5, 3]))
fig.update_layout(paper_bgcolor="#303030")

dcc.Graph(figure=fig)

Again, thanks for letting me know - nice catch :slightly_smiling_face: