Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## matplotlib-users

 [Matplotlib-users] bar plot with different filling patterns From: Francesco Davide Calabrese - 2007-01-20 16:37:09 Attachments: Message as HTML ```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). Please, note that I'm not talking about the borders of 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. Any help will be very appreciated. Thanks and regards Francesco ```
 Re: [Matplotlib-users] bar plot with different filling patterns From: John Hunter - 2007-01-21 16:59:43 ```>>>>> "Francesco" == Francesco Davide Calabrese writes: Francesco> Hi, the following simple code (in Matlab syntax): Francesco> x1 = [5, 6] y1 = [3, 2] bar([1,2], [x1; y1]) Francesco> produces a bar plot where two of the bars have a color Francesco> (let's say red) and the two other bars have another Francesco> color (let's say blue). I'd like to know whether it's Francesco> possible in matplotlib to plot the bars not simply with Francesco> a different color but with a different filling Francesco> pattern. So, for example, the blue bars filled with Francesco> vertical lines (or something else) and the red bars Francesco> filled with horizontal lines (or again something else). Francesco> Please, note that I'm not talking about the borders of Francesco> the bars. The reason why I need this feature is that I Francesco> have to clearly distinguish the bars also when they are Francesco> plotted in black and white, because many publications Francesco> 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 using gradient images. By adding horizontal, vertical, or diangonal 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 ax = fig.add_subplot(111, xlim=xlim, ylim=ylim, 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 ```