Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get rid of plotly bar chart background color

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading