1
$\begingroup$

I am trying to superimpose two plots: a ContourPlot and a LogLogPlot. Even though they both have the same range individually, when I "show" both of them, the range of one is wrong (depending on which plot comes first in "show").

Here are the plots:

pl1 = LogLogPlot[(5*10^15)/x, {x, 10^(-7), 10^(-3)}]
pl2 = ContourPlot[a^(-2/3)*b^-2, {a, 10^(-3), 10^(-7)}, {b, 10^8, 10^23}, 
  ScalingFunctions -> {"Log10", "Log10", "Log10"}]

Then when I run

Show[{pl1, pl2}, PlotRange -> All]

the two plots do not overlap even though they should. Running them in reverse order:

Show[{pl2, pl1}, PlotRange -> All]

gives a different (and also incorrect) result

$\endgroup$
3
  • $\begingroup$ Have you tried setting PlotRange->All individually in both original plots? $\endgroup$
    – Carl Lange
    Commented Jan 28, 2020 at 21:40
  • $\begingroup$ That doesn't seem to help. They give the same result $\endgroup$ Commented Jan 28, 2020 at 21:42
  • $\begingroup$ @J.M. that I had not seen. Sorry $\endgroup$
    – user49048
    Commented Jan 29, 2020 at 1:27

1 Answer 1

4
$\begingroup$

The Show command uses the options from the first graphic that you feed to it, see here

This explains why when you are re-ordering the graphics you get different results. It is to be expected.

In order to fix that: since, show knows what it is doing just don't use the PlotRange command.

The following piece of code

pl1 = Plot[(5*10^15)/x, {x, 10^(-7), 10^(-3)}, ScalingFunctions -> {"Log10", "Log10"}, 
    PlotStyle -> {Thick, White}]; 
pl2 = ContourPlot[1/(a^(2/3)*b^2), {a, 10^(-3), 10^(-7)}, {b, 10^8, 10^23}, 
    ScalingFunctions -> {"Log10", "Log10", "Log10"}]; 
Show[pl2, pl1]

gives

plot

Is this what you wanted?

$\endgroup$

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