You are reading documentation for the unreleased version of Matplotlib. Try searching for the released version of this page instead?
Applications are open for the 2018 John Hunter Matplotlib Summer Fellowship. Apply now!
Version 2.2.2.post1772+gd9240e24b
Fork me on GitHub

Table Of Contents

Related Topics

Barcode Demo

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

import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility

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

axprops = dict(xticks=[], yticks=[])
barprops = dict(aspect='auto',, interpolation='nearest')

fig = plt.figure()

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

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


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

Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery