# Fill a region between horizontal lines and curves

How can I fill the region between two horizontal lines and two curves like the following?

Plot[{Sqrt[(b^2 - 1)/b^2], -Sqrt[(b^2 - 1)/b^2]}, {b, -4, 4},
PlotStyle -> ColorData[97][1], GridLines -> {{}, {1, -1}},
GridLinesStyle -> {Thick, ColorData[97][1]}]

• See here for a related discussion, but it is a few years old. Jul 7 at 9:23

Try this:

Show[{
Plot[{1, -1}, {b, -4, 4}, PlotStyle -> ColorData[97][1],
Filling -> {1 -> {2}}],
Plot[{Sqrt[(b^2 - 1)/b^2], -Sqrt[(b^2 - 1)/b^2]}, {b, -4, 4},
PlotStyle -> ColorData[97][1], Filling -> {1 -> {2}},
FillingStyle -> White]
}]


Have fun!

This sets the background to LightBlue and then fills everything but the center region white.

Plot[{Sqrt[(b^2 - 1)/b^2], -Sqrt[(b^2 - 1)/b^2],1,-1}, {b, -4.08, 4.08}, PlotStyle -> ColorData[97][1],Background->LightBlue,Filling->{1->{{2},White},3->{Top,White},4->{Bottom,White}},PlotRangePadding->None,ImagePadding->None,PlotRange->{-1.08,1.08}]


Edit

Clear[plot, pts];
plot =
Plot[{Sqrt[(b^2 - 1)/b^2], -Sqrt[(b^2 - 1)/b^2]}, {b, -4, 4},
PlotPoints -> 50, MaxRecursion -> 2];
pts = Cases[plot, Line[pts_] :> pts, Infinity];
(*Graphics[{Polygon[Join[pts[[1]],pts[[2]]]],Polygon[Join[pts[[3]],\
pts[[4]]]]}]*)
Graphics[{EdgeForm[Blue], FaceForm[Green],
Polygon@Join[pts[[1]], Reverse@pts[[3]], Reverse@pts[[4]],
pts[[2]]]}, Axes -> True, AspectRatio -> 1/GoldenRatio]


Plot[{Sqrt[(b^2 - 1)/b^2], -Sqrt[(b^2 - 1)/b^2]}, {b, -4, 4},
MaxRecursion -> 10] /. {___, Line[pts1_],
Line[pts2_]} -> {FaceForm@Green, Polygon@Join[pts1, pts2]}

ContourPlot[
x^2 - y^2 == 1, {x, -2, 2}, {y, -2, 2}] /. {__, Line[pts1_],
Line[pts2_]} :> {FaceForm@Green, EdgeForm@Blue,
Polygon@Join[pts1, pts2]}


Original

Use RegionDifference to get the complement of Filling -> {1 -> {2}.

plot0 = Plot[{-Sqrt[(b^2 - 1)/b^2], Sqrt[(b^2 - 1)/b^2]}, {b, -4, 4},
AspectRatio -> 1, Filling -> {1 -> {2}}]

reg = RegionDifference[Rectangle[{-4, -1}, {4, 1}],
DiscretizeGraphics[plot0]];
plot = Plot[{Sqrt[(b^2 - 1)/b^2], -Sqrt[(b^2 - 1)/b^2]}, {b, -4, 4},
PlotStyle -> ColorData[97][1]];
Show[plot, Graphics[{Orange, reg}]]