Something like the following should do the trick:
from pylab import figure, show, cm, nx
from matplotlib.colors import LinearSegmentedColormap
# make a binary, black and white colormap
cmapdata = {
'red' : ((0., 1., 1.), (1., 0., 0.)),
'green': ((0., 1., 1.), (1., 0., 0.)),
'blue' : ((0., 1., 1.), (1., 0., 0.))
}
binary = LinearSegmentedColormap('binary', cmapdata, 2)
fig = figure()
# a vertical barcode
x = nx.mlab.rand(500,1)
x[x>0.8] = 1.
x[x<=0.8] = 0.
ax = fig.add_axes([0.1, 0.3, 0.1, 0.6], xticks=, yticks=)
ax.imshow(x, aspect='auto', cmap=binary)
# a horizontal barcode
x = nx.mlab.rand(1,500)
x[x>0.8] = 1.
x[x<=0.8] = 0.
ax = fig.add_axes([0.3, 0.1, 0.6, 0.1], xticks=, yticks=)
ax.imshow(x, aspect='auto', cmap=binary)
show()
···
On 2/13/07, Giorgio Gilestro <giorgio@...1462...> wrote:
I have a long list composed of either 0s or 1s.
I would like to plot the sequence as a horizontal bar in which 0 = black
pixel, 1 = white pixel
- something looking like a barcode, if you know what I mean.
Is there a way do to that with matplotlib?