# Combining two ListPlots with different y scales

I need to plot two ListPlots on two time-series with different scales, and draw both y axes separately. IE, something like this

This resource function provides this functionality for regular Plot, but it fails to reposition the second axes for ListPlot. Is there a better alternative?

combPlot = ResourceFunction["CombinePlots"];
xs = Range[100];
ys1 = xs;
ys2 = 10 xs + 10;
plot1 = ListPlot[Transpose[{xs, ys1}]]
plot2 = ListPlot[Transpose[{xs, ys2}], FrameStyle -> Red,
Frame -> True, PlotStyle -> Red]
combPlot[plot1, plot2]


• Do the answers to this question address the issue. Commented Mar 6, 2023 at 18:34
• The answer say to use CombinePlot resource function, which has the issue described Commented Mar 6, 2023 at 18:35
• Sorry - this question referenced in the comments has a good answer that doesn't use CombinePlots. Commented Mar 6, 2023 at 18:40
• Aha, that indeed solve the issue. TLDR; combine two plots with Overlay, and move y-axis to the right using Frame -> {False, False, False, True}, FrameTicks -> {{False, All}, {False, False}} Commented Mar 6, 2023 at 18:49
• Your plots do not match the code. Were you using ListLogPlot for red set of points? Commented Mar 6, 2023 at 19:58

I'm surprised the easiest result (built-in functionality) was not yet mentioned:

xs = Range[100];
ys1 = xs^2;
ys2 = 10 xs + 10;
data1 = Transpose[{xs, ys1}];
data2 = Transpose[{xs, ys2}];
ListPlot[{data1, data2}, MultiaxisArrangement -> All]


• good find, this seems like a new feature in 13 Commented Mar 11, 2023 at 22:37

Alternatively,

Clear["Global*"]

xs = Range[100];
ys1 = xs;
ys2 = 10 xs + 10;

ResourceFunction["MultipleAxesListPlot"][
{Transpose[{xs, ys1}], Transpose[{xs, ys2}]},
PlotStyle -> {Automatic, Red},
"SecondaryAxesColor" -> Red,
PlotLegends -> Placed[{"plot1", "plot2"},
{.3, .7}]]


ResourceFunction["MultipleAxesListPlot"][
{Transpose[{xs, ys1}], Transpose[{xs, ys2}]},
Joined -> True,
PlotStyle -> {Automatic, {Red, Dashed}},
"SecondaryAxesColor" -> Red,
PlotLegends -> Placed[{"plot1", "plot2"},
{.3, .7}]]


ResourceFunction["CombinePlots"] does support ListPlot (in fact, it should support all 2D plot types, and any combination of them). You are simply missing some options:

combPlot = ResourceFunction["CombinePlots"];
xs = Range[100];
ys1 = xs;
ys2 = 10 xs + 10;
plot1 = ListPlot[Transpose[{xs, ys1}], Frame -> True]
plot2 = ListPlot[Transpose[{xs, ys2}], FrameStyle -> Red,
Frame -> True, PlotStyle -> Red]
combPlot[plot1, plot2, "AxesSides" -> "TwoY"]


First, note the added Frame->True option for the first plot: like Show, CombinePlots will use options from the first plot where applicable, including the Frame->False option. Second, note the "AxesSides" -> "TwoY" option needed to actually tell CombinePlots` on which axes to put the individual plots.

• You are right, that does that trick Commented Mar 9, 2023 at 19:32