'How to force geopandas to plot a map with "missing values" (legend) in a columns without "missing values"?
I want to make some maps (each column is a date), and for some columns (aka dates) there are some missing values, and for others are not. When I used the function within geopandas "missing_kwds" to highlight missing values (for some regions). When there are NaNs values in the columns (date) the code works fine, but when there are no NaNs in the column I got an Error saying "local variable 'merged_kwds' referenced before assignment". Notice, that I want to keep the in the legend the "missing values" indicator, regardless if that columns (aka date) has not NaNs(I'm collecting the figures and creating a GIF).
for i in geo_cases.iloc[:,:-2]:
fig, ax = plt.subplots(figsize = (12, 12))
# Set the global map
world.plot(color = '#e5e3e6', ax = ax, edgecolor = 'w', linewidth = 0.8)
# set out map
geo_cases.plot(column = geo_cases[i], ax =ax, cmap = 'RdPu', legend = True, alpha = .4,
linewidth = 0.3, edgecolor = 'w', categorical = True, missing_kwds={
"color": "lightgrey",
"edgecolor": "red",
"hatch": "///",
"label": "Missing values"})
Solution 1:[1]
By making another polygone with missing vlaues.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mohamed Hachaichi |