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

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

.. _sphx_glr_gallery_images_contours_and_fields_barcode_demo.py:


============
Barcode Demo
============





.. image:: /gallery/images_contours_and_fields/images/sphx_glr_barcode_demo_001.png
    :class: sphx-glr-single-img





.. code-block:: python

    import matplotlib.pyplot as plt
    import numpy as np

    # Fixing random state for reproducibility
    np.random.seed(19680801)


    # the bar
    x = np.where(np.random.rand(500) > 0.7, 1.0, 0.0)

    axprops = dict(xticks=[], yticks=[])
    barprops = dict(aspect='auto', cmap=plt.cm.binary, interpolation='nearest')

    fig = plt.figure()

    # a vertical barcode -- this is broken at present
    ax = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops)
    ax.imshow(x.reshape((-1, 1)), **barprops)

    # a horizontal barcode
    ax = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops)
    ax.imshow(x.reshape((1, -1)), **barprops)


    plt.show()


.. _sphx_glr_download_gallery_images_contours_and_fields_barcode_demo.py:


.. only :: html

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



  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

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