Shade in Region between two lines - Makie

Hi,

In Makie I can plot two linear lines with the code

x = LinRange(0,100,101)
f = Figure();
ax = Axis(f[1,1])
lines!(x, 30 .+ 0.6*x, color = :blue, label = "Lower")
lines!(x, 2 .+ 1.1*x, color = :blue, label = "Upper")
f

Which produces

How do I shade the region between two lines? I have looked around however could not find anything :slight_smile:

Thanks,
Harry

Is this good enough?

x = LinRange(0,100,101)
y1 = 30 .+ 0.6*x
y2 = 2 .+ 1.1*x
f = Figure();
ax = Axis(f[1,1])
lines!(x, y1, color = :blue, label = "Lower")
lines!(x, y2, color = :blue, label = "Upper")
band!(x, min.(y1, y2), max.(y1, y2), color=:gray)
f

3 Likes

That looks great however it appears to not be translating to my specifc example below.

using CairoMakie
Rx = [60.71240911738448, 37.42373426994792, 32.73403282607647, 68.79877294000902, 40.90366474229968, 27.662881216851964, 77.36130873647507, 39.17049701533512, 23.44241520138802, 101.23841397849756, 82.70063267712554, 74.62678435017145, 111.42556391921549, 87.50902990071828, 71.72816904304429, 121.67397025935885, 88.54622809696518, 69.4486907110057, 121.52688961488205, 105.91408848352084, 95.34451680402904, 133.74315013164957, 111.7104975707231, 93.93560370624327, 145.77351470799502, 115.25299378452297, 93.02912916570061, 132.5626310381735, 118.60407443779617, 106.38806865945602, 146.25782547288068, 125.07320763170928, 105.93378818979255, 159.64155386997098, 130.4167774462154, 105.9139264555842, 138.974199692349, 125.9921076763924, 112.71708548857124, 153.68372141746195, 132.91543752251155, 112.87417490762438, 168.0205934086395, 139.4896476881672, 113.43099505426655, 142.90756009265039, 130.53546974835683, 116.57107158633043, 158.3101999763238, 137.7715658389586, 117.13248130630433, 173.31056709962792, 145.1871313440884, 118.07449220091303, 145.43077956693847, 133.459735086787, 119.03648775838005, 161.314190682643, 140.9172274554381, 119.87453215844776, 176.78110943066469, 148.91808670172352, 121.08244366892586, 147.10930897293622, 135.41342496252972, 120.67742096283222, 163.33311679131126, 143.03209467982833, 121.71103575939904, 179.13387714993414, 151.44919398968094, 123.10822525591148, 148.25926063919866, 136.75890600534797, 121.80494097934026, 164.72922362030002, 144.49800644784602, 122.98092047272795, 180.77348664588493, 153.21775833061264, 124.51664054223937, 68.32741182499467, 61.90434620870666, 57.71829940676398, 68.54286728943532, 55.13780307933787, 54.61082164350387, 68.74356476509799, 53.52208515802596, 51.360071364701916, 96.27537499766973, 89.7820422626889, 86.04064546428323, 98.30695925499572, 84.72222154987989, 83.8318773814027, 99.64544012813397, 83.6595243283454, 81.48191787207529, 112.68160248761401, 104.97456790087072, 101.79200423960327, 115.72176726793856, 101.35788402836522, 100.20228530824123, 117.70665712475687, 100.60282636443378, 98.52208176955982, 122.31879886872159, 113.61134721870368, 110.87114549596207, 125.98923469916406, 111.0352741197453, 109.70256757085379, 128.77501774737965, 110.46783400741923, 108.48873266847835, 128.19279692228065, 118.76096972826387, 116.33330314883737, 132.3644404761502, 116.90332287522838, 115.45316935572754, 135.69629517930449, 116.4616339183412, 114.56344196130848, 131.9118384288736, 121.97391738444017, 119.76180781579679, 136.44387335457142, 120.61186743208185, 119.08358786454252, 140.16734614575424, 120.26027680575736, 118.42180984938489, 134.35059751055002, 124.06035889949067, 121.99711619869876, 139.14758796182886, 123.04509306724522, 121.46405854431116, 143.15026749380664, 122.76113819530921, 120.9653092827746, 135.99962366594457, 125.46184640810196, 123.50274799103133, 140.9945039305116, 124.6941283480249, 123.07677697010911, 145.2011436971441, 124.46263917851384, 122.6977374794462, 137.1440834838542, 126.43006372376237, 124.54497160357316, 142.28675611508802, 125.84275245599406, 124.19992432110521, 146.64847868815042, 125.65303533018947, 123.91080384965258, 18.876307830857574, 22.872522534393465, 33.28060366628129, 18.74892487286866, 30.86278614933403, 42.75493567474384, 23.556428112661074, 36.204988116814086, 49.18102839444623, 26.80336706564883, 39.77701784853379, 53.68527221415125, 29.035289159928077, 42.343267943181424, 56.905884215722104, 18.284727850720866, 23.95120219919211, 18.661940935869435, 23.773639169719992, 26.637211105623372, 37.61081780401049, 16.530127400289917, 17.42707335681768, 24.235093421150072, 32.42329456173831, 32.59636610500108, 47.73888191965294, 20.245782631883436, 23.316048825723303, 28.20841640628888, 38.70307689679933, 36.90400885600979, 55.30478823197116, 13.021283668827888, 16.41908876692619, 18.49000828076302, 25.61653534947066, 22.079312921259092, 16.030283198479175, 24.08048179893934, 23.208183138579173, 31.696395439400657, 33.287434229640496, 37.61296512713094, 20.094130953849724, 30.724101553792345, 27.450960308991508, 40.77690027513047, 38.253922937784935, 48.84183954708166, 22.711583939593353, 35.18920244079958, 30.182514298431734, 47.1615640383294, 41.596150295229364, 57.04315566553329, 24.476817540209264, 38.29964162291382, 32.07257353867673, 51.743516920864906, 43.83784509355326, 63.128688230314786, 25.688214887192107, 40.508492476606314, 33.356364415017865, 55.09269139664384, 45.45386587215741, 67.69486081681197, 15.04192924106381, 18.26587129153226, 17.264083315107417, 21.61121748248937, 21.9627899625803, 38.94986381796609, 45.96796399487748, 20.08601905629496, 42.40935263778791, 54.29594694859139, 46.04355046140588, 60.9069049079075, 50.83516884636829, 64.1736386952043, 36.24319757864877, 54.060419849997295, 74.92040750767701, 33.83047954055966, 58.596264211434736, 84.50850011364359, 31.346365912008654, 57.35781930413109, 74.27632984167498, 45.01162292347624, 60.67041283351189, 86.90362770361446, 43.3841530481958, 65.7054013676715, 99.10583164669656, 41.789308610218434, 61.18446977262464, 80.23991530223257, 50.111434909573525, 64.57233024510381, 94.20908711038817, 48.99031962719789, 69.88370523497785, 108.41400247484817, 47.97888006426854, 63.54983897774853, 83.95274585736587, 53.283688890198974, 66.99630220464915, 98.86502812523047, 52.4791021371433, 72.49685459444012, 114.54158793018048, 51.85863741840615, 65.07527722615427, 86.36932257692231, 55.33758885385929, 68.56661106499617, 101.95034389979482, 54.757612705808825, 74.20019012458397, 118.7013727821266, 54.40683820932992, 66.0936699104705, 88.00103867565994, 56.71819407369455, 69.61999976285708, 104.06433683943894, 56.30622393123985, 75.34926594846168, 121.60547326025899, 56.149154581836704, 66.79296708294598, 89.13663092764256, 57.677666340515835, 70.34709489336905, 105.55439105396393, 57.39376326303967, 76.1468857725491, 123.68382180754321, 57.3797414154521]
f = Figure();
ax = Axis(f[1,1])
y1 = 21.21 .+ 0.847*[Rx;0]
y2 = -2.64 .+ 1.06*[Rx;0]
lines!([Rx;0], y1, color = :blue, label = "Lower")
lines!([Rx;0], y2, color = :blue, label = "Upper")
band!([Rx;0], min.(y1,y2), max.(y1,y2), color=:gray)
f

The above produces

Not sure what is going on here?

I am pretty sure it is because Rx is not sorted:

x = [1, 5, 2] # NOT sorted
y1 = 2 * x
y2 = -2 * x
f = Figure()
ax = Axis(f[1,1])
lines!(x, y1, color = :blue, label = "Upper")
lines!(x, y2, color = :blue, label = "Upper")
band!(x, min.(y1,y2), max.(y1,y2), color=:gray)

It works when sorted:

x = [1, 2, 5] # sorted
y1 = 2 * x
y2 = -2 * x
f = Figure()
ax = Axis(f[1,1])
lines!(x, y1, color = :blue, label = "Upper")
lines!(x, y2, color = :blue, label = "Upper")
band!(x, min.(y1,y2), max.(y1,y2), color=:gray)

3 Likes

Exactly the solution, thanks for the help!

the fillrange keyword of the plot() function produces a result similar to this


using Plots; gr()

x = LinRange(0,100,101)
yL(x)=30 .+ 0.6*x
yU(x)=2 .+ 1.1*x
plot(x,yL, color = :black, label = "Lower")

plot!(x, yU, color = :blue, label = "Upper")

plot!(yL,25,75, label="", fillrange=yU,fillalpha=0.3, fillcolor=:red)

1 Like