I have the following code:
def get_amp_graph():
ampfig = go.Figure(go.Bar(x=['1540', 'Average'], y=get_amp_acc()))
ampfig.update_layout(plot_bgcolor='rgb(28, 28, 28)')
amp_html = ampfig.to_html (
include_plotlyjs=True,
full_html=False,
)
return amp_html
I want the background color to be rgb(28, 28, 28), but then this happens. How could I make the remaining white also turn rgb(28, 28, 28)
>Solution :
To make the remaining white areas of the plot also have the background color rgb(28, 28, 28), you can set the paper_bgcolor property of the layout to the same color value. Here’s how you can modify your code to achieve this:
import plotly.graph_objects as go
def get_amp_graph():
ampfig = go.Figure(go.Bar(x=['1540', 'Average'], y=get_amp_acc()))
ampfig.update_layout(
plot_bgcolor='rgb(28, 28, 28)',
paper_bgcolor='rgb(28, 28, 28)'
)
amp_html = ampfig.to_html(
include_plotlyjs=True,
full_html=False
)
return amp_html
By setting both plot_bgcolor and paper_bgcolor to rgb(28, 28, 28), you ensure that both the plot area and the surrounding paper area will have the desired background color.