I would like to plot two continuous functions in the same plot, but to each one should correspond a different vertical axis with different values, but having in common the same x axis. I would like also to choose the color of each function. I found this code
TwoAxisListPlot[{f_, g_}, opts___] :=
Module[{fgraph, ggraph, frange, grange, fticks,
gticks}, {fgraph, ggraph} =
MapIndexed[
ListPlot[#, Axes -> True, PlotStyle -> ColorData[1][#2[[1]]],
opts] &, {f, g}]; {frange,
grange} = (PlotRange /.
AbsoluteOptions[#, PlotRange])[[2]] & /@ {fgraph, ggraph};
fticks = N@FindDivisions[frange, 10];
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] /@ {1, 2}, {Automatic, Automatic}},
FrameTicks -> {{fticks, gticks}, {Automatic, Automatic}},
ImageSize -> 800]]
which is valid if the function f and g are a list of points. If I use the following functions
funcf = Table[Sin[x], {x, 0, Pi, Pi/100}];
funcg = Table[Cos[x], {x, 0, Pi, Pi/100}];
in the above code
TwoAxisListPlot[{funcf, funcg}, {Frame -> True, PlotRange -> All,
FrameTicksStyle -> {{Automatic, Automatic}, {Black, Black}},
ColorFunction -> {Black, Red}, Joined -> True, ImageSize -> Large,
FrameLabel -> {{"Mean magnetic field (T)", "(Hz)"}, {"\!\(\*
StyleBox[\"Some\",\nFontColor->GrayLevel[0]]\)\!\(\*
StyleBox[\" \",\nFontColor->GrayLevel[0]]\)\!\(\*
StyleBox[\"parameter\",\nFontColor->GrayLevel[0]]\)", ""}},
BaseStyle -> {FontSize -> 20}}]
I obtain
I would like to implement directly the functions funcf and funcg defined together with the range where they are defined. Indeed in the attached figure the x axis does not corresponds to the range [0,Pi]. In addition, I would like also to choose the colors of the two functions from the command option (for example one black and the other one red).

TwoAxisListPlot. – MarcoB Mar 21 '21 at 14:10