stbamb stbamb - 2 months ago 5x
Python Question

Matplotlib questions

Possible Duplicate:

Plotting with Python

I've been using Matprolib for plotting. I've found it very useful, but I dont know exactly how to use the 'fill_between()' function. I have tried several times to fix it but I cant get to the point.

I have been studying several tutorials, but I havent found very useful ones (according to my task).

My task is to fill the area that all lines have in common, just like this:


And this is what the system does:


Is there any way to do it? Anyone knows how to use 'fill_between()' in a correct way?

Ken Ken

You can use the where option. As in the example you can do something like:

fill_between(x, myzero, y1, where=y2>=y1, facecolor='blue', interpolate=True)

Where y2 is the line that is sometimes on top. You will have do do this for each of the lines, though.

Another option is to define a minimum of the functions and fill below that, though you will either need to know before hand that the ys are defined at the same points or use interpolation so that they are all defined at the same points.

mymin = np.minimum(y1,y2,y3)
fill_between(x, myzero, mymin)

Hope that helps.

Edit: To find the minimum from several functions which are all defined for the same x-values you can use the following:

def OverallMinimum(*ys):
    mymin = y[0].copy()
    for y in ys:
        min = np.minimum(mymin,y)
    return mymin

Then you can use the second fill_between from above to plot between zero and the minimum from that function.