{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Broken horizontal bars\n\n`~.Axes.broken_barh` creates sequences of horizontal bars. This example shows\na timing diagram.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\n# data is a sequence of (start, duration) tuples\ncpu_1 = [(0, 3), (3.5, 1), (5, 5)]\ncpu_2 = np.column_stack([np.linspace(0, 9, 10), np.full(10, 0.5)])\ncpu_3 = np.column_stack([10*np.random.random(61), np.full(61, 0.05)])\ncpu_4 = [(2, 1.7), (7, 1.2)]\ndisk = [(1, 1.5)]\nnetwork = np.column_stack([10*np.random.random(10), np.full(10, 0.05)])\n\nfig, ax = plt.subplots()\n# broken_barh(xranges, (ypos, height))\nax.broken_barh(cpu_1, (\"CPU 1\", 0.4), align=\"center\")\nax.broken_barh(cpu_2, (\"CPU 2\", 0.4), align=\"center\")\nax.broken_barh(cpu_3, (\"CPU 3\", 0.4), align=\"center\")\nax.broken_barh(cpu_4, (\"CPU 4\", 0.4), align=\"center\")\nax.broken_barh(disk, (\"disk\", 0.4), align=\"center\", color=\"tab:orange\")\nax.broken_barh(network, (\"network\", 0.4), align=\"center\", color=\"tab:green\")\nax.set_xlim(0, 10)\nax.invert_yaxis()  # order the bars from top to bottom\nax.set_title(\"Resource usage\")\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.broken_barh` / `matplotlib.pyplot.broken_barh`\n   - `matplotlib.axes.Axes.invert_yaxis`\n   - `matplotlib.axes.Axes.set_yticks`\n\n.. tags::\n\n   component: annotation\n   plot-type: bar\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.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}