Plotly - cant seem to change default gray background to White/Transparent background

Viewed 11

I have code below like

# Add data
year = d['year']

Revenue = d['revenue']
Count = d['count']

# Create and style traces
trace0 = go.Scatter(
    x = year,
    y = Revenue,
    name = 'Revenue',
    line = dict(
        color = ('rgb(255, 255, 102)'),
        width = 4)
)
trace1 = go.Scatter(
    x = year,
    y = Count,
    name = 'Count',
    yaxis='y2',
    line = dict(
        color = ('rgb(8,48,107)'),
        width = 4,
        dash = 'dash'),
    
    
)
data = [trace0, trace1]

# Edit the layout
layout = dict(title = 'Reject Rates - Spring 2017 through YTD 2018',
              xaxis = dict(title = 'Weekly Progession'),
              yaxis = dict(title = 'Rejects per delivery'),
              yaxis2 = dict(title='Minutes',
              overlaying='y',
        side='right',
        titlefont=dict(
            color= ('rgb(8,48,107)'),
        ),
        tickfont=dict(
            color=('rgb(8,48,107)')
     )))
              
fig = dict(data=data, layout=layout)
                            
iplot(fig)

How can I make the background of the plot white and not the default gray? Thanks!

1 Answers

You're looking for the plot_bgcolor key. Therefore, you'd adjust the following:

layout = dict(title = 'Reject Rates - Spring 2017 through YTD 2018',
              xaxis = dict(title = 'Weekly Progession'),
              yaxis = dict(title = 'Rejects per delivery'),
              yaxis2 = dict(title='Minutes',
              plot_bgcolor = "rgb(0, 0, 0)",
              ... # rest of your layout
     )))

And if you need to adjust the background of the area outside the plot, you can use the paper_bgcolor key.

Related