imod.visualize.plot_map#

imod.visualize.plot_map(raster, colors, levels, overlays=[], basemap=None, kwargs_raster=None, kwargs_colorbar=None, kwargs_basemap={}, figsize=None, return_cbar=False, fig=None, ax=None)[source]#

Plot raster on a map with optional vector overlays and basemap.

Parameters:
  • raster (xr.DataArray) – 2D grid to plot.

  • colors (list of str, list of RGBA/RGBA tuples, colormap name (str), or) –

    LinearSegmentedColormap.

    If list, it should be a Matplotlib acceptable list of colors. Length N. Accepts both tuples of (R, G, B) and hexidecimal (e.g. #7ec0ee).

    If str, use an existing Matplotlib colormap. This function will autmatically add distinctive colors for pixels lower or high than the given min respectivly max level.

    If LinearSegmentedColormap, you can use something like matplotlib.cm.get_cmap(‘jet’) as input. This function will not alter the colormap, so add under- and over-colors yourself.

    Looking for good colormaps? Try: http://colorbrewer2.org/ Choose a colormap, and use the HEX JS array.

  • levels (listlike of floats or integers) – Boundaries between the legend colors/classes. Length: N - 1.

  • overlays (list of dicts, optional) – Dicts contain geodataframe (key is “gdf”), and the keyword arguments for plotting the geodataframe.

  • basemap (bool or contextily._providers.TileProvider, optional) –

    When True or a contextily._providers.TileProvider object: plot a basemap as a background for the plot and make the raster translucent. If basemap=True, then CartoDB.Positron is used as the default provider. If not set explicitly through kwargs_basemap, plot_map() will try and infer the crs from the raster or overlays, or fall back to EPSG:28992 (Amersfoort/RDnew).

    Requires contextily

  • kwargs_raster (dict of keyword arguments, optional) – These arguments are forwarded to ax.imshow()

  • kwargs_colorbar (dict of keyword arguments, optional) – These arguments are forwarded to fig.colorbar(). The key label can be used to label the colorbar. Key whiten_triangles can be set to False to alter the default behavior of coloring the min / max triangles of the colorbar white if the value is not present in the map.

  • kwargs_basemap (dict of keyword arguments, optional) – Except for “alpha”, these arguments are forwarded to contextily.add_basemap(). Parameter “alpha” controls the transparency of raster.

  • figsize (tuple of two floats or integers, optional) – This is used in plt.subplots(figsize)

  • return_cbar (boolean, optional) – Return the matplotlib.Colorbar instance. Defaults to False.

  • fig (matplotlib.figure, optional) – If provided, figure to which to add the map

  • ax (matplot.ax, optional) – If provided, axis to which to add the map

Returns:

  • fig (matplotlib.figure ax : matplotlig.ax if return_cbar == True: cbar :)

  • matplotlib.Colorbar

Examples

Plot with an overlay:

>>> overlays = [{"gdf": geodataframe, "edgecolor": "black", "facecolor": "None"}]
>>> imod.visualize.plot_map(raster, colors, levels, overlays)

Label the colorbar:

>>> imod.visualize.plot_map(raster, colors, levels, kwargs_colorbar={"label":"Head aquifer (m)"})

Plot with a basemap:

>>> import contextily as ctx
>>> src = ctx.providers.Stamen.TonerLite
>>> imod.visualize.plot_map(raster, colors, levels, basemap=src, kwargs_basemap={"alpha":0.6})