# Filling only parts of a ListLinePlot

I have a set of {x,y} data that shows a measurement value over time on the x axis. I'd like to highlight several chunks of time on my ListLinePlot by filling the plot to the axis for only certain x-ranges (say, 10-20 and 55-96).

I've tried the methods outlined here: ListLinePlot partial filling

data1 = movavgjoined; data1[[;; 9]] = Null; data1[[21 ;;]] = Null;
ListLinePlot[{movavgjoined, data1}, Filling -> {2 -> Axis}]


But the output is just the original graph.

Edit: here's some sample data

movavgjoined = {{0.00416667,5.50648},{0.00833333,5.51119},{0.0125,5.51531},
{0.0166667,5.51983},{0.0208333,5.52381},{0.025,5.52728},{0.0291667,5.53126},
{0.0333333,5.53551},{0.0375,5.53966},{0.0416667,5.54449},{0.0458333,5.54942},
{0.05,5.55455},{0.0541667,5.55929},{0.0583333,5.56368},{0.0625,5.56793},
{0.0666667,5.57214},{0.0708333,5.57568},{0.075,5.57774},{0.0791667,5.57921},
{0.0833333,5.58106},{0.0875,5.58391},{0.0916667,5.5875},{0.0958333,5.59185},
{0.1,5.59556},{0.104167,5.59932},{0.108333,5.60445},{0.1125,5.61067},
{0.116667,5.61925},{0.120833,5.62737},{0.125,5.63508},{0.129167,5.64551},
{0.133333,5.65654},{0.1375,5.665},{0.141667,5.67078},{0.145833,5.67456},
{0.15,5.67668},{0.154167,5.67757},{0.158333,5.67719},{0.1625,5.67757},
{0.166667,5.68031}};


## 1 Answer

yintervals = {{5.55, 5.58}, {5.61, 5.66}};
data2 = If[IntervalMemberQ[IntervalUnion @@ (Interval /@ yintervals), #[[2]]],
#, {#[[1]], Null}] & /@ movavgjoined;

ListLinePlot[{movavgjoined, data2}, Filling -> {2 -> Axis}, PlotStyle -> ColorData[97][1]]


xintervals = {{.05, .08}, {.11, .13}};
data3 = If[IntervalMemberQ[IntervalUnion @@ (Interval /@ xintervals), #[[1]]],
#, {#[[1]], Null}] & /@ movavgjoined;

ListLinePlot[{movavgjoined, data3}, Filling -> {2 -> Axis}, PlotStyle -> ColorData[97][1]]


• Thank you for your suggestion! Okay so this is working but it's filling the wrong part of my plot. I think this is because these functions call the nth list element rather than as a range of y values. My y values are time values in minutes/fractions of minutes and are irregularly spaced. So the 10th-20th time point is being filled as opposed to 10 minutes-20 minutes. – user63997 May 6 '19 at 4:34
• @user63997, it would be easier to suggest a solution if you can post your movavgjoined. – kglr May 6 '19 at 4:37
• True! I edited the original post with some sample data. It's a big list, so I just included the first few points so you get the idea. – user63997 May 6 '19 at 4:53
• Shoot, I see now that I made a mistake in my original post. The X axis is the time points, not the Y. So the above code uses a y-range which you've defined. The graph is exactly what I'm wanting, though. So say here instead of defining the y values, the time ranges on the x axis that I'd like to fill are {0.5, 0.8} and {0.11,0.13}. Would the code be the same? – user63997 May 6 '19 at 7:19
• @user63997, updated with the version that uses intervals of x-coordinates. – kglr May 6 '19 at 7:31