{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Interpolations for imshow\n\nThis example displays the difference between interpolation methods for\n`~.axes.Axes.imshow`.\n\nIf *interpolation* is None, it defaults to the :rc:`image.interpolation`.\nIf the interpolation is ``'none'``, then no interpolation is performed for the\nAgg, ps and pdf backends. Other backends will default to ``'auto'``.\n\nFor the Agg, ps and pdf backends, ``interpolation='none'`` works well when a\nbig image is scaled down, while ``interpolation='nearest'`` works well when\na small image is scaled up.\n\nSee :doc:`/gallery/images_contours_and_fields/image_antialiasing` for a\ndiscussion on the default ``interpolation='auto'`` option.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nmethods = [None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16',\n 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric',\n 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos']\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\ngrid = np.random.rand(4, 4)\n\nfig, axs = plt.subplots(nrows=3, ncols=6, figsize=(9, 6),\n subplot_kw={'xticks': [], 'yticks': []})\n\nfor ax, interp_method in zip(axs.flat, methods):\n ax.imshow(grid, interpolation=interp_method, cmap='viridis')\n ax.set_title(str(interp_method))\n\nplt.tight_layout()\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.imshow` / `matplotlib.pyplot.imshow`\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.2" } }, "nbformat": 4, "nbformat_minor": 0 }