# Fill below certain threshold

How can I insert Fill in the plot below, such that only the area below 0.5 and below the line is filled?

Plot[-x + 1, {x, 0, 1}]


EDIT: I was hoping the solution to this simpler question would also work for my real problem, which involves the following data, but this is not the case:

How can I implement you solution on this data?

Using Michael's solution combined with comments by void life

Plot[{data  , Min[1/2, #] & data }, {x, 0, 1}, PlotStyle -> {Automatic,None}, Filling -> {1 -> 0, 2 -> {{1}, White}}]


I get:

{0.744318, 0.60038, 0.539471, 0.5542, 0.592916, 0.613237, 0.673014, 0.687572, 0.658548, 0.69416, 0.65248, 0.653574, 0.596889, 0.577856, 0.592349, 0.505633, 0.51403, 0.520655, 0.492696, 0.459513, 0.463524, 0.463181, 0.415386, 0.422303, 0.422072, 0.406222, 0.40379, 0.389445, 0.375038, 0.349756, 0.332508, 0.323173, 0.308245, 0.290745, 0.285053, 0.275322, 0.268835, 0.25514, 0.25281, 0.254935, 0.250978, 0.251613, 0.25431, 0.251915, 0.252345, 0.253374, 0.253928, 0.248666, 0.25169, 0.253212, 0.257687, 0.257374, 0.256379, 0.262966, 0.263945, 0.268633, 0.270197, 0.273909, 0.274298, 0.275465, 0.274321, 0.273316}


• Plot[{-x + 1, Min[1/2, -x + 1]}, {x, 0, 1}, PlotStyle -> {Automatic, None}, Filling -> {2 -> 0}]? Jan 13 '19 at 19:46
• I see the trick. Jan 13 '19 at 19:47
• What is the problem with using Michael's method with your data? Plot your data and Min[1/2,#]& data in the same way as the example. Jan 13 '19 at 21:16
• @void life See my latest edit Jan 13 '19 at 21:28
• Sorry I meant Min[1/2, #]& /@ data. You need to actually Map the values of data to the function. Secondly, Plot takes a function not just a bunch of data points. You need to use ListLinePlot or similar or create a function that will return values from your data. E.g ListLinePlot[{data, Min[1/2, #] & /@ data}, PlotStyle -> {Automatic, None}, Filling -> {1 -> 0, 2 -> {{1}, White}}] will give you what you are after Jan 13 '19 at 21:37

Possibly also this:

Plot[{-x + 1, Min[1/2, -x + 1]}, {x, 0, 1},
PlotStyle -> {Automatic, None},
Filling -> {1 -> 0, 2 -> {{1}, White}}]


• I have edited my question. I set out to provide a simple example, but it turns out my real problem may not be solved so easily using your otherwise instructive example. Jan 13 '19 at 20:26
data = {0.744318, 0.60038, 0.539471, 0.5542, 0.592916, 0.613237,
0.673014, 0.687572, 0.658548, 0.69416, 0.65248, 0.653574, 0.596889,
0.577856, 0.592349, 0.505633, 0.51403, 0.520655, 0.492696,
0.459513, 0.463524, 0.463181, 0.415386, 0.422303, 0.422072,
0.406222, 0.40379, 0.389445, 0.375038, 0.349756, 0.332508,
0.323173, 0.308245, 0.290745, 0.285053, 0.275322, 0.268835,
0.25514, 0.25281, 0.254935, 0.250978, 0.251613, 0.25431, 0.251915,
0.252345, 0.253374, 0.253928, 0.248666, 0.25169, 0.253212,
0.257687, 0.257374, 0.256379, 0.262966, 0.263945, 0.268633,
0.270197, 0.273909, 0.274298, 0.275465, 0.274321, 0.273316};

threshold = 0.5;

Show[Plot[data, {x, 0, 1}, PlotStyle -> {Automatic, None}],
Plot[threshold, {x, 0, 1}, Filling -> Min@data]]


Or

Show[Plot[data, {x, 0, 1}, PlotStyle -> {Automatic, None},
PlotRange -> {0.2, 0.8}],
Plot[threshold, {x, 0, 1}, Filling -> 0.2]]