I frequently generate framed plots like this:
Plot[Sin[x], {x, 0, 2 π}, Frame -> True]

Is there an easy way to change the background color of the framed region only?
Specifying the Background option unfortunately changes the background color of the entire plot, not just the framed region:
Plot[Sin[x], {x, 0, 2 π}, Frame -> True, Background -> LightGray]

Also, is there a way to make figures look like MATLAB's default figure style, i.e. a white background surrounded by a gray frame (see below)?

Answer
You can use the Prolog option with Scaled coordinates:
Plot[Sin[x], {x, 0, 2 π}, Frame -> True,
Prolog -> {LightGray, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}
]

Note: Using scaled coordinates lets this work for any PlotRangePadding, and with PlotRangePadding->False:
Plot[Sin[x], {x, 0, 2 π}, Frame -> True,
Prolog -> {LightGray, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]},
PlotRangePadding -> .6]

Plot[Sin[x], {x, 0, 2 π}, Frame -> True,
Prolog -> {LightGray, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]},
PlotRangePadding -> -.2, PlotRangeClipping -> False]

Comments
Post a Comment