Frame coordinates of a Plot for background filling

I want to fill the frame background of a Plot with a color for which I am using a Rectangle as a Prolog item.

p1 = Plot[{Sin[2 x], Sin[x]}
, {x, 0, 2 \[Pi]}
, Frame -> {{True, True}, {True, True}}
, FrameTicks -> Automatic
, Prolog -> {
Nest[Lighter, Brown, 5]
, Rectangle[{0, -1.0}, {2 \[Pi], 1.0}]
}
] Using AbsoluteOptions gives the same values that have been used in the Prolog section above, but it leaves a small margin.

AbsoluteOptions[#, PlotRange] & @p1

{PlotRange -> {{0., 6.28319}, {-1., 1.}}}

EDIT-1

I know PlotRangePadding->None would get me there, but I want to find the coordinates of the frame box.

Question(s)

1. How do I determine the frame bounding box coordinates inside the Prolog section so that I can put a Rectangle there to fill the frame with a specified color.

2. Are there built-in options (or other available solutions) for this purpose?

• AbsoluteOptions has been heavily upgraded and improved in V13. If you evaluate AbsoluteOptions[p1, PlotRangePadding] in V12, you get measurements in the form of Scaled[]. In V13, however, you get PlotRangePadding -> {{0.1309, 0.1309}, {0.111111, 0.111111}}. You can subtract this from coordinates (and add to size of the rectangle) and you will be able to fill the whole area. To do this, I would first plot and use Epilog -> a, then get the AbsoluteOptions and replace p1 /. a -> {Nest ...}. Jan 3 at 10:53

You can use Scaled and avoid the need for explicit coordinates:

Plot[{Sin[2 x], Sin[x]}, {x, 0, 2 π},
Frame -> True,
Prolog -> {Nest[Lighter, Brown, 5],
Rectangle[Scaled[{-1, 1}], Scaled[{1, -1}]]}] Update: In case you need the plot range for other purposes, you can use undocumented function Chartingget2DPlotRange:

Plot[{Sin[2 x], Sin[x]}, {x, 0, 2 π}, Frame -> True,
DisplayFunction ->
(Show[#,
Prolog -> {Nest[Lighter, Brown, 5],
Rectangle @@ Transpose[Chartingget2DPlotRange @ #]}] &)] • I'd expect that you should be able to use Rectangle[Scaled[{-1, 1}], Scaled[{1, -1}]] regardless of the version. Jan 3 at 18:06
• Thank you @Brett. I somehow got some warning message containing ".. Absolute..." first time I used Rectangle[Scaled[{-1, 1}], Scaled[{1, -1}]] in version 13.0 (on Wolfram Cloud) and the message went away when I switched to Rectangle[Scaled[{-1, 1},{0,0}], Scaled[{1, -1},{0,0}]]. (The message was probably triggered by some other option as I cannot reproduce it now).
– kglr
Jan 3 at 18:11
• Rectangle[Scaled[{0, 0}], Scaled[{1, 1}] also fills the frame: Can you please explain the -1s in the Scaled as docs mention "... coordinates scaled to run from 0 to 1 across the whole plot range in each direction". Thanks for the answer.
– Syed
Jan 3 at 18:41
• Yes, {0,0} and {1,1} are what I would normally use here. Jan 3 at 18:47
• @Syed, as Brett commented, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}] is the better alternative here. (Although they also work, the alternative forms Rectangle[Scaled[{-1,1}], Scaled[{1, -1}], Rectangle[Scaled[{-1,-1}], Scaled[{1, 1}] etc are based on my having used to the two-argument form of Scaled)
– kglr
Jan 3 at 19:03