
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/lines_bars_and_markers/broken_barh.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_lines_bars_and_markers_broken_barh.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_lines_bars_and_markers_broken_barh.py:


======================
Broken horizontal bars
======================

`~.Axes.broken_barh` creates sequences of horizontal bars. This example shows
a timing diagram.

.. GENERATED FROM PYTHON SOURCE LINES 9-35

.. code-block:: Python

    import matplotlib.pyplot as plt
    import numpy as np

    # data is a sequence of (start, duration) tuples
    cpu_1 = [(0, 3), (3.5, 1), (5, 5)]
    cpu_2 = np.column_stack([np.linspace(0, 9, 10), np.full(10, 0.5)])
    cpu_3 = np.column_stack([10*np.random.random(61), np.full(61, 0.05)])
    cpu_4 = [(2, 1.7), (7, 1.2)]
    disk = [(1, 1.5)]
    network = np.column_stack([10*np.random.random(10), np.full(10, 0.05)])

    fig, ax = plt.subplots()
    # broken_barh(xranges, (ymin, height))
    ax.broken_barh(cpu_1, (-0.2, 0.4))
    ax.broken_barh(cpu_2, (0.8, 0.4))
    ax.broken_barh(cpu_3, (1.8, 0.4))
    ax.broken_barh(cpu_4, (2.8, 0.4))
    ax.broken_barh(disk, (3.8, 0.4), color="tab:orange")
    ax.broken_barh(network, (4.8, 0.4), color="tab:green")
    ax.set_xlim(0, 10)
    ax.set_yticks(range(6),
                  labels=["CPU 1", "CPU 2", "CPU 3", "CPU 4", "disk", "network"])
    ax.invert_yaxis()
    ax.set_title("Resource usage")

    plt.show()



.. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_broken_barh_001.png
   :alt: Resource usage
   :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_broken_barh_001.png, /gallery/lines_bars_and_markers/images/sphx_glr_broken_barh_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 36-50

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.axes.Axes.broken_barh` / `matplotlib.pyplot.broken_barh`
   - `matplotlib.axes.Axes.invert_yaxis`
   - `matplotlib.axes.Axes.set_yticks`

.. tags::

   component: annotation
   plot-type: bar
   level: beginner


.. _sphx_glr_download_gallery_lines_bars_and_markers_broken_barh.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: broken_barh.ipynb <broken_barh.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: broken_barh.py <broken_barh.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: broken_barh.zip <broken_barh.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
