Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > bf21b4394f4d7fa09e3626145d3315e0 > files > 304

python-matplotlib-doc-1.2.0-14.fc18.i686.rpm

.. _pylab_examples-barcode_demo:

pylab_examples example code: barcode_demo.py
============================================



.. plot:: /builddir/build/BUILD/matplotlib-1.2.0/doc/mpl_examples/pylab_examples/barcode_demo.py

::

    from matplotlib.pyplot import figure, show, cm
    from numpy import where
    from numpy.random import rand
    
    # the bar
    x = where(rand(500)>0.7, 1.0, 0.0)
    
    axprops = dict(xticks=[], yticks=[])
    barprops = dict(aspect='auto', cmap=cm.binary, interpolation='nearest')
    
    fig = figure()
    
    # a vertical barcode -- this is broken at present
    x.shape = len(x), 1
    ax = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops)
    ax.imshow(x, **barprops)
    
    x = x.copy()
    # a horizontal barcode
    x.shape = 1, len(x)
    ax = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops)
    ax.imshow(x, **barprops)
    
    
    show()
    
    

Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)