File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 3737import cartopy .crs as ccrs
3838import geopandas as gpd
3939import matplotlib as mpl
40+ import matplotlib .patches as mpatches
4041import matplotlib .pyplot as plt
4142import numpy as np
4243import requests
@@ -420,8 +421,7 @@ def geo_im_from_array(
420421
421422 # prepare colormap
422423 cmap = plt .get_cmap (kwargs .pop ("cmap" , CMAP_RASTER ))
423- cmap .set_bad ("gainsboro" ) # For NaNs and infs
424- cmap .set_under ("white" , alpha = 0 ) # For values below vmin
424+ cmap .set_under ("white" ) # For values below vmin
425425
426426 # Generate each subplot
427427 for array_im , axis , tit , name in zip (
@@ -470,6 +470,15 @@ def geo_im_from_array(
470470 cmap = cmap ,
471471 ** kwargs ,
472472 )
473+ # handle NaNs in griddata
474+ color_nan = "gainsboro"
475+ if np .any (np .isnan (grid_im )):
476+ no_data_patch = mpatches .Patch (color = color_nan , label = "NaN" )
477+ axis .legend (
478+ handles = [no_data_patch ] + axis .get_legend_handles_labels ()[0 ],
479+ loc = "lower right" ,
480+ )
481+ axis .set_facecolor (color_nan )
473482 cbar = plt .colorbar (img , cax = cbax , orientation = "vertical" )
474483 cbar .set_label (name )
475484 axis .set_title ("\n " .join (wrap (tit )))
You can’t perform that action at this time.
0 commit comments