# Generate Plots with Two Vertical Scales [duplicate]

I was trying to generate a plot with two different y axis, i found a post in the wolfram forum about this topic it's called the TwoAxisPlot but it doesn't work like it's described, here's the code from the wolfram page

TwoAxisPlot[{f_, g_}, {x_, x1_, x2_}] :=
Module[{fgraph, ggraph, frange, grange, fticks,
gticks}, {fgraph, ggraph} =
MapIndexed[
Plot[#, {x, x1, x2}, Axes -> True,
PlotStyle -> ColorData[#2[]]] &, {f, g}]; {frange,
grange} = (PlotRange /. AbsoluteOptions[#, PlotRange])[[
2]] & /@ {fgraph, ggraph}; fticks = N@FindDivisions[frange, 5];
gticks = Quiet@
Transpose@{fticks,
ToString[NumberForm[#, 2], StandardForm] & /@
Rescale[fticks, frange, grange]};
Show[fgraph,
ggraph /.
Graphics[graph_, s___] :>
Graphics[
GeometricTransformation[graph,
RescalingTransform[{{0, 1}, grange}, {{0, 1}, frange}]], s],
Axes -> False, Frame -> True,
FrameStyle -> {ColorData /@ {1, 2}, {Automatic, Automatic}},
FrameTicks -> {{fticks, gticks}, {Automatic, Automatic}}]]


this is the example that they give to you

TwoAxisPlot[{Sin[x], 3 Sin[x] + 5 Cos[x]}, {x, 0, 4 Pi}]


this is my code and what i tried

sol = NDSolve[{Ca'[t] ==
25 - 0.005 Ca[t] - 8 10^12 E^(-22500/(1.987 T[t] )) Ca[t],
T'[t] ==
0.005 (300 - T[t]) +
0.01 (8 10^12 E^(-22500/(1.987 T[t] ))) Ca[t] -
0.001 (T[t] - 330), Ca == 5000, T == 330}, {Ca, T}, {t,
1500}]
Plot[{Ca[t], T[t]} /. sol, {t, 0, 1000}, PlotRange -> All]
TwoAxisPlot[{f_, g_}, {x_, x1_, x2_}] :=
Module[{fgraph, ggraph, frange, grange, fticks,
gticks}, {fgraph, ggraph} =
MapIndexed[
Plot[#, {x, x1, x2}, Axes -> True,
PlotStyle -> ColorData[#2[]]] &, {f, g}]; {frange,
grange} = (PlotRange /.
AbsoluteOptions[#, PlotRange])[] & /@ {fgraph, ggraph};
fticks = N@FindDivisions[frange, 5];
gticks =
Quiet@Transpose@{fticks,
ToString[NumberForm[#, 2], StandardForm] & /@
Rescale[fticks, frange, grange]};
Show[fgraph,
ggraph /.
Graphics[graph_, s___] :>
Graphics[
GeometricTransformation[graph,
RescalingTransform[{{0, 1}, grange}, {{0, 1}, frange}]], s],
Axes -> False, Frame -> True,
FrameStyle -> {ColorData /@ {1, 2}, {Automatic, Automatic}},
FrameTicks -> {{fticks, gticks}, {Automatic, Automatic}}]]

TwoAxisPlot[{Ca[t], T[t]}, {t, 0, 1000}]


this is the example this is how my plot should be any idea on how to manipulate the code from the wolfram page to make it work with these functions? here's the link to the article https://reference.wolfram.com/language/howto/GeneratePlotsWithTwoVerticalScales.html

thanks a lot, any help would be kindly and hugely appreciated

• Does TwoAxisPlot[{Ca[t], T[t]} /. Flatten@sol, {t, 0, 1000}] give the expected result? – LouisB Mar 13 at 8:14
• You may also be interested in 1 plot / 2 scale and CombinePlots. – LouisB Mar 13 at 8:22
• It does, thanks @LouisB – Sosa Mar 13 at 17:57