1

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!

Britzel
  • 663
  • 3
  • 10

1 Answers1

4

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

Tim Laska
  • 16,346
  • 1
  • 34
  • 58