TwoAxisPlot[{f_, g_}] :=
Module[{fgraph, ggraph, frange, grange, fticks,
gticks}, {fgraph, ggraph} =
MapIndexed[
ListPlot[#, Axes -> True,
PlotStyle -> ColorData[1][#2[[1]]]] &, {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] /@ {1, 2}, {Automatic, Automatic}},
FrameTicks -> {{fticks, gticks}, {Automatic, Automatic}}]]
举个例子:
a = {{0, 1020.7}, {24.2, 1352.4}, {37.5, 1259.1}, {44.4, 1203}};
b = {{0, 22.238}, {24.2, 17.084}, {37.5, 14.51}, {44.4, 12.68}};
TwoAxisPlot[{a, b}]
参考文献:
[1] Wolfram语言与系统参考资料中心. https://reference.wolfram.com/language/howto/GeneratePlotsWithTwoVerticalScales.html