There are numerous questions here on combining two plots (usually ListPlots), but (as far as I can see) none with quite what I seek. I would like to make a single plot consisting of two functions, each with the same abscissa (x range) but different ordinates (y range), in both offset and scale. I want the left Frame axis to be in one style (blue) and the right Frame axis to be in another (red). Inserting is extremely awkward because the spatial extents of the tick labels, offsets, scales, padding, and so on all differ.
Here is how far I've gotten:
pt1 = Plot[1 + Sin[x], {x, 1, 5},
PlotRange -> {0, 3},
PlotStyle -> Blue,
Frame -> {{True, False}, {True, False}},
FrameStyle -> {{Blue, None}, {Black, None}}]
pt2 = Plot[80 + 50 Cos[x^2],
{x, 1, 5},
PlotRange -> {1, All},
AxesOrigin -> {1, 20},
PlotStyle -> Red,
Frame -> {{False, True}, {True, False}},
FrameStyle -> {{None, Red}, {Black, None}},
FrameTicks -> {{None, Range[20, 140, 10]}, {Automatic, None}}]
I would like to combine these into a single plot, where the left frame axis goes from 0 to 3 while the right axis goes from 20 to 120. That is, the same height in the graph should correspond to 0 on the left and 20 on the right, and the same height in the graph should correspond to 3 on the left and 120 on the right.
Show[pt1,pt2]
simply does not work:
I can change aspect ratios and offsets by hand but surely there is a more direct way.
r1 = {0, 3}; r2 = {20, 140}; Plot[{1 + Sin[x], Rescale[80 + 50 Cos[x^2], r2, r1]}, {x, 1, 5}, PlotRange -> {0, 3}, PlotStyle -> {Blue, Red}, Frame -> {{True, True}, {True, False}}, FrameTicks -> {{Automatic, Charting`FindTicks[r1, r2][##] &}, {Automatic, Automatic}}, FrameStyle -> {{Blue, Red}, {Black, None}}]
? $\endgroup$