{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Contour corner mask\n\nIllustrate the difference between ``corner_mask=False`` and\n``corner_mask=True`` for masked contour plots. The default is controlled by\n:rc:`contour.corner_mask`.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\n# Data to plot.\nx, y = np.meshgrid(np.arange(7), np.arange(10))\nz = np.sin(0.5 * x) * np.cos(0.52 * y)\n\n# Mask various z values.\nmask = np.zeros_like(z, dtype=bool)\nmask[2, 3:5] = True\nmask[3:5, 4] = True\nmask[7, 2] = True\nmask[5, 0] = True\nmask[0, 6] = True\nz = np.ma.array(z, mask=mask)\n\ncorner_masks = [False, True]\nfig, axs = plt.subplots(ncols=2)\nfor ax, corner_mask in zip(axs, corner_masks):\n cs = ax.contourf(x, y, z, corner_mask=corner_mask)\n ax.contour(cs, colors='k')\n ax.set_title(f'{corner_mask=}')\n\n # Plot grid.\n ax.grid(c='k', ls='-', alpha=0.3)\n\n # Indicate masked points with red circles.\n ax.plot(np.ma.array(x, mask=~mask), y, 'ro')\n\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `matplotlib.axes.Axes.contour` / `matplotlib.pyplot.contour`\n - `matplotlib.axes.Axes.contourf` / `matplotlib.pyplot.contourf`\n\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.13.5" } }, "nbformat": 4, "nbformat_minor": 0 }