bar plot with different filling patterns

Hi, the following simple code (in Matlab syntax):

> x1 = [5, 6] y1 = [3, 2] bar([1,2], [x1; y1])

> produces a bar plot where two of the bars have a color
> (let's say red) and the two other bars have another
> color (let's say blue). I'd like to know whether it's
> possible in matplotlib to plot the bars not simply with
> a different color but with a different filling
> pattern. So, for example, the blue bars filled with
> vertical lines (or something else) and the red bars
> filled with horizontal lines (or again something else).
> the bars. The reason why I need this feature is that I
> have to clearly distinguish the bars also when they are
> plotted in black and white, because many publications
> can't be done in colors.

The postscript backend supports this -- we call it "hatching".
Unfortunately, the others do not yet. See the example at
http://matplotlib.sf.net/examples/hatch_demo.py

One could be clever with "imshow" and create arrays that have the
hatching. In the example I wrote below I created a custom bar chart
lines to the arrays, or dots, one could support various hatching
schemes. Here is the sample code for gradients that i wrote in
response to an earlier post:

from pylab import figure, show, nx, cm

def gbar(ax, x, y, width=0.5, bottom=0):
X = [[.6, .6],[.7,.7]]
for left,top in zip(x, y):
right = left+width
ax.imshow(X, interpolation='bicubic', cmap=cm.Blues,
extent=(left, right, bottom, top), alpha=1)

fig = figure()

xmin, xmax = xlim = 0,10
ymin, ymax = ylim = 0,1
autoscale_on=False)
X = [[.6, .6],[.7,.7]]

ax.imshow(X, interpolation='bicubic', cmap=cm.copper,
extent=(xmin, xmax, ymin, ymax), alpha=1)

N = 10
x = nx.arange(N)+0.25
y = nx.mlab.rand(N)
gbar(ax, x, y, width=0.7)
ax.set_aspect('normal')
show()

Ideally, we could do the work in Agg to support these hatched
images....

JDH