From: Andrew S. <str...@as...> - 2004-09-28 16:15:27
|
On Sep 28, 2004, at 5:15 AM, John Hunter wrote: >>>>>> "Dirk" == <rep...@we...> writes: > > Dirk> I want to fill the area between two curves with a color > Dirk> (incl. alpha channel, I use the agg backend). fill() seems > Dirk> to fill only the area between the x-axis and one curve - at > Dirk> least I found no way for filling only the area between two > Dirk> graphs. Is there a way for doing so at all? Or do I have to > Dirk> use another graphic library for this kind of fill_between()? > > All of the matplotlib plot commands create primitive objects > (lines.Line2D, patches.Rectangle, patches.Polygon, text.Text). If a > plot command doesn't suit your needs, you can roll your own by > creating the right kind of primitive object. Here is a fill_between > implementation The fill() command itself does work if you give it coordinates for a closed polygon. This draws a filled spiral: from matplotlib.matlab import * from numarray import * theta = arange(0,8*pi,0.1) a=1 b=.2 for dt in arange(0,2*pi,pi/2.0): x = a*cos( theta+dt )*exp(b*theta) y = a*sin( theta+dt )*exp(b*theta) dt = dt+pi/4.0 x2 = a*cos( theta+dt )*exp(b*theta) y2 = a*sin( theta+dt )*exp(b*theta) xf = concatenate( (x,x2[::-1]) ) yf = concatenate( (y,y2[::-1]) ) p1=fill(xf,yf) show() |