|
37 | 37 | import cartopy.crs as ccrs |
38 | 38 | import geopandas as gpd |
39 | 39 | import matplotlib as mpl |
| 40 | +import matplotlib.patches as mpatches |
40 | 41 | import matplotlib.pyplot as plt |
41 | 42 | import numpy as np |
42 | 43 | import requests |
@@ -374,6 +375,11 @@ def geo_im_from_array( |
374 | 375 | ------- |
375 | 376 | cartopy.mpl.geoaxes.GeoAxesSubplot |
376 | 377 |
|
| 378 | + Notes |
| 379 | + ----- |
| 380 | + Data points with NaN or inf are plotted in gray. White regions correspond to |
| 381 | + regions outside the convex hull of the given coordinates. |
| 382 | +
|
377 | 383 | Raises |
378 | 384 | ------ |
379 | 385 | ValueError |
@@ -420,8 +426,7 @@ def geo_im_from_array( |
420 | 426 |
|
421 | 427 | # prepare colormap |
422 | 428 | 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 |
| 429 | + cmap.set_under("white") # For values below vmin |
425 | 430 |
|
426 | 431 | # Generate each subplot |
427 | 432 | for array_im, axis, tit, name in zip( |
@@ -470,6 +475,17 @@ def geo_im_from_array( |
470 | 475 | cmap=cmap, |
471 | 476 | **kwargs, |
472 | 477 | ) |
| 478 | + # handle NaNs in griddata |
| 479 | + color_nan = "gainsboro" |
| 480 | + if np.any(np.isnan(x) for x in grid_im): |
| 481 | + no_data_patch = mpatches.Patch( |
| 482 | + facecolor=color_nan, edgecolor="black", label="NaN" |
| 483 | + ) |
| 484 | + axis.legend( |
| 485 | + handles=[no_data_patch] + axis.get_legend_handles_labels()[0], |
| 486 | + loc="lower right", |
| 487 | + ) |
| 488 | + axis.set_facecolor(color_nan) |
473 | 489 | cbar = plt.colorbar(img, cax=cbax, orientation="vertical") |
474 | 490 | cbar.set_label(name) |
475 | 491 | axis.set_title("\n".join(wrap(tit))) |
|
0 commit comments