# Two ListLinePlots together with two vertical axes [duplicate]

I have two data sets data1 and data2:

SeedRandom[1];
data1 = Sort[RandomReal[1, {10, 2}]];
data2 = Sort[RandomReal[2, {10, 2}]];


I would like to plot both data sets in one common plot with two different colors.

• the left vertical scale should extend from 0 to 1 for plot1
• the right vertical scale should extend from 0 to 2 for plot2

How can I do that?

• @Kuba: Thank this seems to help ... but I do now see any numbers at the right axis: imgur.com/a/fwypI
– lio
Feb 10, 2017 at 14:24
• @Kuba: Could you please show the code for my example? I am not able to make it running.
– lio
Feb 10, 2017 at 14:33
• @JasonB. it is at least documented. If your code fails one can't even complain.
– Kuba
Feb 10, 2017 at 15:14

SeedRandom[1];
data1 = Sort[RandomReal[1, {10, 2}]];
data2 = Sort[RandomReal[2, {10, 2}]];


Something about the grouping for Frame, FrameStyle and FrameTicks is a bit out of date in the previous answer. Try

plot1 = ListPlot[data1,
PlotRange -> {{0, 1}, {0, 1}},
PlotStyle -> Blue,
Frame -> {{True, False}, {True, True}},
FrameStyle -> {{Blue, Automatic}, {Blue, Blue}}
]


plot2 = ListPlot[data2,
PlotRange -> {{0, 1}, {0, 2}},
PlotStyle -> Red,
Axes -> False,
Frame -> {{False, True}, {False, False}},
FrameTicks -> {{None, All}, {None, None}},
FrameStyle -> {{Automatic, Red}, {Automatic, Red}}
]


Overlay[{plot1, plot2}]


• Thank you for your help. Why is the right vertical axis (red) not positioned at x=1?
– lio
Feb 10, 2017 at 14:58
• @lio I am away from my computer. Maybe try ImagePadding as in previous answer Feb 10, 2017 at 15:29
• Great ... yes this has to be added: for both plots ImagePadding -> 25,. Could you please update your answer?
– lio
Feb 10, 2017 at 15:44
• @lio Updated with ImagePadding Feb 10, 2017 at 16:55
• Is it possible to align the y-axes? If I have one data set with just positive y values and another one with also negative y values then the two y-axes are misaligned. AxesOrigin doesn't seem to work here. Jul 17, 2019 at 12:15