It looks to me, when running your code, that fill_over is
> doing the right thing: filling everything between 0.5 and
> your plotted line with a color. It is just that with
> your coarse spacing, you don't have points at every
> multiple of pi/2. However, this is with the current CVS
> version, so you may have a problem with 0.60.2.
Probably what Philipp is looking for is for fill_over to do some
linear interpolation between his data points, which I think gives the
least surprising results. The attached code probably comes closer to
what he's looking for. It's probably a useful function to include in
the library - see if it meets your needs
from matplotlib.matlab import *
def fill_over(ax, x, y, val, color, over=True):
"""
Plot filled x,y for all y over val
If over = False, fill under
"""
x = asarray(x).astype(nx.Float32)
y = asarray(y).astype(nx.Float32)
ybase = asarray(y)-val
crossings = nonzero(less(ybase[:-1] * ybase[1:],0))
on = not over
indLast = 0
for ind in crossings:
if not on:
on = not on
indLast = ind
continue
thisX = array(x[indLast:ind+2])
thisY = array(y[indLast:ind+2])
#find the x point between x[0] and x[1] on the line
#connecting them such that f(x) = 0.5
#if len(thisX)<3: continue
m = (thisY[1]-thisY[0])/(thisX[1]-thisX[0])
x0 = (val-thisY[0])/m+thisX[0]
thisX[0] = x0
thisY[0] = val
# now get the last point on the interpolated line
m = (thisY[-1]-thisY[-2])/(thisX[-1]-thisX[-2])
xend = (val-thisY[-2])/m+thisX[-2]
thisX[-1] = xend
thisY[-1] = val
on = not on
ax.fill(thisX, thisY, color)
indLast = ind
x=arange(0.0, 20.0, 1.0)
y = sin(x)
plot(x,y, 'ro-')
fill_over(gca(), x, y, 0.5, '#0000FF', over=True)
show()