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

.. only:: html

    .. 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
============

This demo shows how to produce a one-dimensional image, or "bar code".

.. GENERATED FROM PYTHON SOURCE LINES 8-33

.. code-block:: default

    import matplotlib.pyplot as plt
    import numpy as np

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

    # the bar
    x = np.random.rand(500) > 0.7

    barprops = dict(aspect='auto', cmap='binary', interpolation='nearest')

    fig = plt.figure()

    # a vertical barcode
    ax1 = fig.add_axes([0.1, 0.1, 0.1, 0.8])
    ax1.set_axis_off()
    ax1.imshow(x.reshape((-1, 1)), **barprops)

    # a horizontal barcode
    ax2 = fig.add_axes([0.3, 0.4, 0.6, 0.2])
    ax2.set_axis_off()
    ax2.imshow(x.reshape((1, -1)), **barprops)

    plt.show()




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





.. GENERATED FROM PYTHON SOURCE LINES 34-41

------------

References
""""""""""

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

.. GENERATED FROM PYTHON SOURCE LINES 42-46

.. code-block:: default


    import matplotlib
    matplotlib.axes.Axes.imshow
    matplotlib.pyplot.imshow




.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none


    <function imshow at 0x7f73be827820>




.. _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 sphx-glr-download-python

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



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

     :download:`Download Jupyter notebook: barcode_demo.ipynb <barcode_demo.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>`_
