1
$\begingroup$

I would like to shade a horizontal region in LogLogPlot as in the figure below. Logarithmic plot with horizontal shading The figure on the left is done with LogLogPlot:

LogLogPlot[x^2, {x, 10^-10, 10^5}, Frame -> True, GridLines -> Automatic, GridLinesStyle -> Directive[Dashed, LightGray], PlotLegends -> Placed[LineLegend[{Automatic}, {"y=\!\(\*SuperscriptBox[\(x\), \ \(2\)]\)"}], {.88, .15}]]

I am able to achieve the desired effect (figure on the right) by combining the plot with a RegionPlot:

f1 = Plot[Log[10, (10^xvar)^2], {xvar, -10, 5}, Axes -> False];
f2 = RegionPlot[-4 < xvar < 1, {xvar, -10, 5}, {yvar, -21, 11}, BoundaryStyle -> None, PlotStyle -> Directive[Antialiasing -> True, Hue[1, .6, 1, .3]], PlotLegends -> Placed[LineLegend[{Automatic}, {"y=\!\(\*SuperscriptBox[\(x\), \ \(2\)]\)"}], {.88, .12}]];
xticks = Table[{x, Superscript[10, ToString[x]]}, {x, -10, 5, 3}];
yticks = Table[{x, Superscript[10, ToString[x]]}, {x, -21, 11, 10}];
Show[{f1, f2}, Frame -> True, GridLines -> Automatic, GridLinesStyle -> Directive[Dashed, LightGray], Epilog -> {Text[Style["Awesome region", Hue[1, .5, .8]], Scaled[{0.54, 0.8}]]}, FrameTicks -> {{yticks, None}, {xticks, None}}]

However, this seems like a very inefficient way of doing such a simple thing as I have to map the logarithmic scales (because RegionPlot doesn't support log scales) and then map the ticks to get the right labels. Surely there must be a way of doing this in LogLogPlot directly.

$\endgroup$
3
  • 1
    $\begingroup$ You can combine to LogLogPlots but the second should show the function like Piecewise@{{10^-22,x<10^-4},{10^10,10^-4<x<7*10^-2}} with Filling->Axis $\endgroup$
    – Rom38
    Commented Jun 9, 2017 at 5:42
  • $\begingroup$ Thanks, that's much simpler. Should have thought of it. $\endgroup$
    – Philo
    Commented Jun 9, 2017 at 6:37
  • $\begingroup$ Do you agree it is an essence a duplicate of: How does epilog position work in logplots? $\endgroup$
    – Kuba
    Commented Jun 9, 2017 at 7:49

1 Answer 1

4
$\begingroup$

Try this:

Show[{
  LogLogPlot[x^2, {x, 10^-10, 10^5}, Frame -> True, 
   GridLines -> Automatic, 
   GridLinesStyle -> Directive[Dashed, LightGray], 
   PlotLegends -> 
    Placed[LineLegend[{Automatic}, {"y=\!\(\*SuperscriptBox[\(x\), \ \
\(2\)]\)"}], {.88, .15}]],

  LogLogPlot[10^12, {x, 10^-4, 5}, PlotRange -> {10^-21, 10^12}, 
   Filling -> Bottom, FillingStyle -> Directive[Pink, Opacity[0.5]]]
  }]

enter image description here

Have fun!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.