条形码示例
该演示展示了如何生成一维图像或“条形码”。
import matplotlib.pyplot as pltimport numpy as np# Fixing random state for reproducibilitynp.random.seed(19680801)# the barx = 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 barcodeax1 = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops)ax1.imshow(x.reshape((-1, 1)), **barprops)# a horizontal barcodeax2 = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops)ax2.imshow(x.reshape((1, -1)), **barprops)plt.show()

参考
此示例中显示了以下函数,方法和类的使用:
import matplotlibmatplotlib.axes.Axes.imshowmatplotlib.pyplot.imshow
