fig = px.choropleth(
df,
geojson=geo_json,
featureidkey="properties.State", # Match this with the key in your GeoJSON properties
locations="State",
color="Transaction_amount",
projection="mercator",
width=900, # Set the desired width
height=700 # Set the desired height
)
# Update the map to fit the GeoJSON data
fig.update_geos(fitbounds="locations", visible=False)
# Set background color to light grey
plot_color='#1F1F1F'
fig.update_layout(
paper_bgcolor=plot_color, # Light grey
plot_bgcolor=plot_color # Light grey
)
# Show the map
fig.show()
The paper_bgcolor will change the color of the outside background
The plot_bgcolor will change the background color of the plotting area in-between x and y axes, so this wonβt work on maps.
Color change on scatter plot:
import plotly.express as px
fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
fig.update_layout(
paper_bgcolor='black', # Change the outside background color
plot_bgcolor='pink' # Change the plot area background color
)
fig.show()
@Mac A map is not referenced to a cartesian system, with axes x, and y, thatβs why paper_bgcolor does not work. Map are rendered in geographical coordinates.
To set your desired background color set the bgcolor in layout geo: