如何摆脱绘图条形图背景颜色

问题描述 投票:0回答:1

我有以下代码:

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

我希望背景颜色是rgb(28,28,28),但是this happens。怎么才能让剩下的白色也变成rgb(28, 28, 28)

plotly
1个回答
0
投票

要使绘图的其余白色区域也具有背景颜色

rgb(28, 28, 28)
,您可以将布局的
paper_bgcolor
属性设置为相同的颜色值。您可以通过以下方式修改代码来实现此目的:

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

通过将

plot_bgcolor
paper_bgcolor
设置为
rgb(28, 28, 28)
,您可以确保绘图区域和周围的纸张区域都具有所需的背景颜色。

© www.soinside.com 2019 - 2024. All rights reserved.