On 2/13/07, Giorgio Gilestro <[EMAIL PROTECTED]> 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?

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()

Attachment: barcode.png
Description: PNG image

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to