# Two overlapping list: plot odd and even from each in different colors

I have two lists produce by a script that are most likely identical (but might not be).

I would like to plot them using ListPlot[] in such a way to display only even elements from the first list and odd elements from the second one, essentially interleaving the two lists. Goal is to show that the two are in fact overlapping.

Sample data is just two identical lists such as

a = Table[y,{y,1,20}];
b = Table[y,{y,1,20}];


My lists come without x coordinates but can be added if needed.

• Can you post example data...? – user6014 Jul 30 at 20:02
• ListPlot[{list1[[;; ;; 2]], list2[[2 ;; ;; 2]]}]? – kglr Jul 30 at 20:04

Using sample data which actually is identical, of the form {x, y}, you can do this with creative use of Part:

data1 = data2 = Table[{x, Sin[x]}, {x, 0, 2 Pi, .1}];

ListPlot[{data1[[1 ;; ;; 2]], data2[[2 ;; ;; 2]]},
PlotStyle -> {Red, Blue}] data1[[1 ;; ;; 2]] takes every 2nd element of data1 starting from element 1, data2[[2 ;; ;; 2]] takes every 2nd element of data2 starting from element 2.

Specifying PlotStyle -> {Red, Blue} isn't explicitly necessary as they sets of data will be different styles by default, but you may wish to control how they look.

• Precisely what I was looking for, thanks! – Three Diag Jul 30 at 20:16
SeedRandom
l = RandomReal[100, 30];
{list1, list2} = Thread[{Range, #}] & /@ ({#, # + RandomReal[{-.05, 05}]} & @ l);

ListPlot[{list1[[;; ;; 2]], list2[[2 ;; ;; 2]]},
PlotLegends -> {"list1", "list2"}, BaseStyle -> PointSize[Large]] 