{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Image nonuniform\n\n`.NonUniformImage` is a generalized image with pixels on a rectilinear grid,\ni.e. it allows rows and columns with individual heights / widths.\n\nThere is no high-level plotting method on `~.axes.Axes` or `.pyplot` to\ncreate a NonUniformImage. Instead, you have to instantiate the image\nexplicitly add it to the Axes using `.Axes.add_image`.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom matplotlib.image import NonUniformImage\n\ninterp = 'nearest'\n\n# Linear x array for cell centers:\nx = np.linspace(-4, 4, 9)\n\n# Highly nonlinear x array:\nx2 = x**3\n\ny = np.linspace(-4, 4, 9)\n\nz = np.sqrt(x[np.newaxis, :]**2 + y[:, np.newaxis]**2)\n\nfig, axs = plt.subplots(nrows=2, ncols=2, layout='constrained')\nfig.suptitle('NonUniformImage class', fontsize='large')\nax = axs[0, 0]\nim = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4),\n                     cmap=\"Purples\")\nim.set_data(x, y, z)\nax.add_image(im)\nax.set_xlim(-4, 4)\nax.set_ylim(-4, 4)\nax.set_title(interp)\n\nax = axs[0, 1]\nim = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4),\n                     cmap=\"Purples\")\nim.set_data(x2, y, z)\nax.add_image(im)\nax.set_xlim(-64, 64)\nax.set_ylim(-4, 4)\nax.set_title(interp)\n\ninterp = 'bilinear'\n\nax = axs[1, 0]\nim = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4),\n                     cmap=\"Purples\")\nim.set_data(x, y, z)\nax.add_image(im)\nax.set_xlim(-4, 4)\nax.set_ylim(-4, 4)\nax.set_title(interp)\n\nax = axs[1, 1]\nim = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4),\n                     cmap=\"Purples\")\nim.set_data(x2, y, z)\nax.add_image(im)\nax.set_xlim(-64, 64)\nax.set_ylim(-4, 4)\nax.set_title(interp)\n\nplt.show()"
      ]
    }
  ],
  "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.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}