{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Bar demo with units\n\nA plot using a variety of centimetre and inch conversions. This example shows\nhow default unit introspection works (ax1), how various keywords can be used to\nset the x and y units to override the defaults (ax2, ax3, ax4) and how one can\nset the xlimits using scalars (ax3, current units assumed) or units\n(conversions applied to get the numbers to current units).\n\n.. only:: builder_html\n\n   This example requires :download:`basic_units.py <basic_units.py>`\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from basic_units import cm, inch\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\ncms = cm * np.arange(0, 10, 2)\nbottom = 0 * cm\nwidth = 0.8 * cm\n\nfig, axs = plt.subplots(2, 2)\n\naxs[0, 0].bar(cms, cms, bottom=bottom)\n\naxs[0, 1].bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch)\n\naxs[1, 0].bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=cm)\naxs[1, 0].set_xlim(2, 6)  # scalars are interpreted in current units\n\naxs[1, 1].bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch)\naxs[1, 1].set_xlim(2 * cm, 6 * cm)  # cm are converted to inches\n\nfig.tight_layout()\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
}