{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Plot maps\n\nThe ``imod.visualize.plot_map`` functionality of iMOD Python allows to create\ncustomized plots.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import the necessary packages:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n\nimport imod" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import the input data to plot:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "tempdir = imod.util.temporary_directory()\n\nlakes = imod.data.lakes_shp(tempdir)\nsurface_level = imod.data.ahn()[\"ahn\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is necessary to define the Matplotlib colorbar to be used and the levels\nfor the legend as a list.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "colors = \"RdYlBu_r\"\nlevels = np.arange(-15, 17.5, 2.5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The next lines show the simplest way to plot the raster.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "imod.visualize.plot_map(surface_level, colors, levels)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is also possible to add an overlay to the previous map\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "overlays = [{\"gdf\": lakes, \"facecolor\": \"black\", \"alpha\": 0.3}]\n\nimod.visualize.plot_map(surface_level, colors, levels, overlays=overlays)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Label the colorbar as follows:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "imod.visualize.plot_map(\n surface_level, colors, levels, kwargs_colorbar={\"label\": \"Surface level (m)\"}\n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And to include a basemap:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import contextily as ctx\n\nsrc = ctx.providers.Stamen.TonerLite\nimod.visualize.plot_map(\n surface_level,\n colors,\n levels,\n basemap=src,\n kwargs_basemap={\"alpha\": 0.6},\n overlays=overlays,\n kwargs_colorbar={\"label\": \"Surface level (m)\"},\n)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 0 }