Hey Plotly-Community,
I am trying to plot a map of Germany with the choropleth_mapbox.
Problem that I have. At the Data not all parts are filled and I want to give this areas another color then the areas where a value is present.
The missing values canβt be filled with the min or max value, else the color of the other areas are changing as well. If I use the theoretical min or max value the colors in the plot come closer together and the color difference does not have much contrast.
What I tried so far:
fig = px.choropleth_mapbox(df,
geojson=geodf.geometry,
locations=df.index,
color=variable,
title=variable,
mapbox_style="white-bg",
zoom=6,
center = {"lat": 51.325691, "lon": 10.451526},
color_continuous_scale=["white", "blue", "red"]
range_color=(np.unique(df[variable])[1], np.max(df[variable])),
hover_data=[variable, df.index],
)
variable
is one variable out of the df
.
i tried to add another choroplethmapbox fig.add_choroplethmapbox
with the entrys that are not filled in the df. so I created a mask and filtered these frames. But the colors changed to another scale and the colorscale from the added choroplethmapbox werenβt used at all.
Now I Created a minimal Example:
from shapely.geometry import Polygon
import geopandas as gpd
import numpy as np
import json
import plotly.express as px
geometry = gpd.GeoSeries([Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]), Polygon([(1, 1), (2, 1), (2, 2), (1, 2)]), Polygon([(1, 0), (2, 0), (2, 1), (1, 1)]), Polygon([(0, 1), (1, 1), (1, 2), (0, 2)])])
geoDf = gpd.GeoDataFrame(data={"Name":["a","b","c","d"], "geometry": geometry}, geometry="geometry")
dataDf = pd.DataFrame(data={"Data":[1,1.5,2,np.nan]})
fig = px.choropleth_mapbox(dataDf,
geojson=geoDf.geometry,
locations=dataDf.index,
color="Data",
title="Data",
mapbox_style="white-bg",
center = {"lat": 1, "lon": 1},
zoom=6.5,
color_continuous_scale=["white", "red"],
#range_color=(np.unique(df[variable])[1], np.max(df[variable])),
hover_name="Data",
)
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
fig.show()
What I want is that the top left corner is filled with another color out of the color_range