{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Inverted axis\n\nThis example demonstrates two ways to invert the direction of an axis:\n\n- If you want to set *explicit axis limits* anyway, e.g. via `~.Axes.set_xlim`, you\n  can swap the limit values: ``set_xlim(4, 0)`` instead of ``set_xlim(0, 4)``.\n- Use `.Axis.set_inverted` if you only want to invert the axis *without modifying\n  the limits*, i.e. keep existing limits or existing autoscaling behavior.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nx = np.arange(0.01, 4.0, 0.01)\ny = np.exp(-x)\n\nfig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6.4,  4), layout=\"constrained\")\nfig.suptitle('Inverted axis with ...')\n\nax1.plot(x, y)\nax1.set_xlim(4, 0)   # inverted fixed limits\nax1.set_title('fixed limits: set_xlim(4, 0)')\nax1.set_xlabel('decreasing x \u27f6')\nax1.grid(True)\n\nax2.plot(x, y)\nax2.xaxis.set_inverted(True)  # inverted axis with autoscaling\nax2.set_title('autoscaling: set_inverted(True)')\nax2.set_xlabel('decreasing x \u27f6')\nax2.grid(True)\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. tags::\n\n   component: axis\n   plot-type: line\n   level: beginner\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.14.7"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}