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

    Click :ref:`here <sphx_glr_download_gallery_lines_bars_and_markers_gradient_bar.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_lines_bars_and_markers_gradient_bar.py:


============
Gradient Bar
============





.. image:: /gallery/lines_bars_and_markers/images/sphx_glr_gradient_bar_001.png
    :class: sphx-glr-single-img





.. code-block:: python

    import matplotlib.pyplot as plt
    import numpy as np

    np.random.seed(19680801)


    def gbar(ax, x, y, width=0.5, bottom=0):
        X = [[.6, .6], [.7, .7]]
        for left, top in zip(x, y):
            right = left + width
            ax.imshow(X, interpolation='bicubic', cmap=plt.cm.Blues,
                      extent=(left, right, bottom, top), alpha=1)


    xmin, xmax = xlim = 0, 10
    ymin, ymax = ylim = 0, 1

    fig, ax = plt.subplots()
    ax.set(xlim=xlim, ylim=ylim, autoscale_on=False)

    X = [[.6, .6], [.7, .7]]
    ax.imshow(X, interpolation='bicubic', cmap=plt.cm.copper,
              extent=(xmin, xmax, ymin, ymax), alpha=1)

    N = 10
    x = np.arange(N) + 0.25
    y = np.random.rand(N)
    gbar(ax, x, y, width=0.7)
    ax.set_aspect('auto')
    plt.show()


.. _sphx_glr_download_gallery_lines_bars_and_markers_gradient_bar.py:


.. only :: html

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



  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
