Transparent background in Choropleth?

Hi everyone,

I have a choropleth map in Python Dash app.
I would like to make the background of the map transparent, so that it matches the style of the external stylesheets, but I cannot figure out why itโ€™s not happening.

Here is the full code:

from dash import Dash, html, dcc
import plotly.graph_objects as go
import dash_bootstrap_components as dbc

fig = go.Figure(go.Scattergeo())

fig.update_layout(
    showlegend=False
)

fig.update_geos(
    projection_type="natural earth",
    showcountries=True,
    showland=True,
    landcolor="LightGreen",
    showocean=True,
    oceancolor="LightBlue",
    showlakes=True,
    lakecolor="LightBlue",
    showrivers=True,
    rivercolor="LightBlue",
)

app = Dash(__name__, external_stylesheets=[dbc.themes.CYBORG])
app.layout = html.Div([
    dcc.Graph(figure=fig)
])

app.run_server(debug=True, use_reloader=False)

I have tried two different options below, but none seems to be working.

fig.update_layout(geo=dict(bgcolor= "rgba(0,0,0,0)"))
fig.update_layout(geo_bgcolor="rgba(0,0,0,0)")

Thanks in advance for any recommendations.

Try this:

fig.update_layout( 
    paper_bgcolor='rgba(0,0,0,0)',
    plot_bgcolor='rgba(0,0,0,0)'
)

Hi @AIMPED ,

Almost worked. There is still some white background.

@mrel
go.Layout.geo has the property bgcolor. To find out more details:

print(help(go.layout.Geo.bgcolor))
Help on property:
Set the background color of the map
    
    The 'bgcolor' property is a color and may be specified as:
      - A hex string (e.g. '#ff0000')
      - An rgb/rgba string (e.g. 'rgb(255,0,0)')
      - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
      - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
      - A named CSS color

hence setting fig.update_geos(bgcolor='rgba(0,0,0,0)')
and , fig.update_layout(paper_bgcolor='rgba(0,0,0,0), youโ€™ll get:

1 Like

Genius!

Thank you very much, @empet , and Happy New Year!

1 Like