TransWikia.com

Plotting two functions into one plot with two y-axes. Is there a built option for this in newer versions of Mathematica?

Mathematica Asked on October 22, 2021

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!

One Answer

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

Answered by Tim Laska on October 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP