1
$\begingroup$

If I combine a Plot with a Rectangle (as following) I obtain the expected result:

fig = Plot[10^-x, {x, 1, 5}];
rec = Graphics[{LightGray, Rectangle[{2, 10^-2}, {3, 10^-4}]}];
Show[rec, fig, Frame -> True, AspectRatio -> .5]

enter image description here

However, If I use LogPlot I obtain the following:

fig = LogPlot[10^-x, {x, 1, 5}]
rec = Graphics[{LightGray, Rectangle[{2, -2}, {3, -4}]}];
Show[rec, fig, Frame -> True, AspectRatio -> .5]

enter image description here

That is, the rectangle is at the correct position but the curve has been shifted. Indeed, fig is now:

enter image description here

Is it a bug or am I doing something wrong?

$\endgroup$

closed as off-topic by Jason B., m_goldberg, JungHwan Min, MarcoB, halirutan Aug 7 '18 at 4:36

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Jason B., m_goldberg, JungHwan Min, MarcoB, halirutan
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Seems a simple enough mistake - you took the base-10 log of your rectangle coordinates, but LogPlot uses the natural log. $\endgroup$ – Jason B. Aug 3 '18 at 21:04
  • $\begingroup$ @Jason B. thanks! You are indeed right! Could you please convert this comment into an answer? $\endgroup$ – Valerio Aug 4 '18 at 10:36
3
$\begingroup$

From the documentation for Show:

Show uses the options from the first graphic

Mathematica graphics

If you change the order you will get the scaling options of the LogPlot instead, including the interpretation of the coordinates

fig = LogPlot[10^-x, {x, 1, 5}];
rec = Graphics[{LightGray, Rectangle[{2, -2}, {3, -4}]}];
Show[fig, rec, Frame -> True, AspectRatio -> .5]

Mathematica graphics

Solution

LogPlot[10^-x
 , {x, 1, 5}
 , Prolog -> {LightGray, Rectangle[{2, Log[10^-2]}, {3, Log[10^-3]}]}
 , PlotTheme -> "Scientific"
 , AspectRatio -> 1/2
 , PlotRange -> {10^-6, 1}
 ]

Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ I see, but how do I obtain the correct plot? $\endgroup$ – Valerio Aug 3 '18 at 20:47
  • $\begingroup$ @Valerio I have updated my answer. $\endgroup$ – rhermans Aug 3 '18 at 21:02
  • $\begingroup$ thanks but I prefer the solution by Jason B. as it uses the original structure; I need indeed to put many objects together. $\endgroup$ – Valerio Aug 4 '18 at 10:37
0
$\begingroup$

We can produce your first image with

Plot[10^-x, {x, 1, 5}, Frame -> True,
 Prolog -> {LightGray, Rectangle[{2, 10^-2}, {3, 10^-3}]}]

I would therefore expect the following to work, and it does.

LogPlot[10^-x, {x, 1, 5}, Frame -> True,
 Prolog -> {LightGray, Rectangle[{2, Log[10^-2]}, {3, Log[10^-3]}]}]

Note that I changed a 4 to a 3; change it back if that's not what you meant.

$\endgroup$

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