2
$\begingroup$

I am looking into possibilities to plot two functions into one Plot, but with separate y-axes. I came across several variants of how to do this when searching for it, such as in this thread here. Other approaches make use of Overlay.

However none of these methods is really simple and user friendly, and since all questions I came across have been asked 5+ years ago, I thought I ask if Mathematica built in this option in the meantime directly into Plot, ParametricPlot, ListPlot, etc.?

Thanks!

$\endgroup$
3
  • 3
    $\begingroup$ There is a resource function called CombinePlots. $\endgroup$
    – Tim Laska
    Commented Jul 20, 2020 at 21:17
  • $\begingroup$ See also How to | Generate Plots with Two Vertical Scales $\endgroup$
    – Bob Hanlon
    Commented Jul 20, 2020 at 21:21
  • $\begingroup$ Thanks for the link to the resource function @Tim Laska ! This would qualify as answer. If you want to give it, I can mark it as such. Thanks also for the link @Bob Hanlon ! This was one of the solutions I came across when searching for it. The CombinePlots resource function seems to be better in the sense that it seems to be more versatile in the sense of parsing options and w. r. t. the question which kind of plots can be used. $\endgroup$
    – Britzel
    Commented Jul 21, 2020 at 11:15

1 Answer 1

5
$\begingroup$

There is a resource function called CombinePlots that is supposed to operate like Show and offers a fair amount of flexibility.

An example usage from the documentation is shown in the following:

cp = ResourceFunction["CombinePlots"];
cp[
 Plot[x^2, {x, 0, 10}, Frame -> True],
 Plot[
  100 x^4, {x, 0, 10},
  ScalingFunctions -> "Log",
  Frame -> True, FrameStyle -> Red, PlotStyle -> Red
  ],
 "AxesSides" -> "TwoY"
 ]

Use case 1

One can easily setup a secondary x and y axes as shown:

cp[
 Plot[Cos[x], {x, 0, 10}, Frame -> True], 
 Plot[1 + 10 Sin[x]^2, {x, 0, 30}, ScalingFunctions -> "Log", 
  Frame -> True, FrameStyle -> Red, PlotStyle -> Red], 
 "AxesSides" -> "TwoXY"
 ]

Use case 2

$\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.