Superimposed (put curves on top of each other) in one region

If I have the following data:

https://pastebin.com/AVFwHkC8

or

https://pastebin.com/6kSJBLkR (this is the same data with two extra sets)

Which plotted like this: ListPlot[data, PlotRange -> All] gives:

Question:

1)How can I make each curve to superimposed (lie on top of each other) in the region between 40 and 65 (x-axis)? 2) How can I give a different color to each curves when plotting the data? UPDATED: 3) How can I put a legend inside the plot with labelling each curve?

How to give a different color?

The raw data is a list of 1400 coordinate points. The data can be reshaped as 5 individual lists of 280 coordinate pairs.

Clear[data]
Get["https://pastebin.com/raw/AVFwHkC8", "Data"];
newshape = ArrayReshape[data, {5, 280, 2}];


Now ListPlot[newshape] will give a different color to each curve.

How to superpose the curves without distortion?

An approximate way is to shift each curve up or down so its 50th data point, say, lies on the x-axis. Plots at different scales show the 5 shifted curves happen to cross one another at points near x=49.54.

shifted = # /. {x_, y_} :> {x, y - #[[50, 2]]} &  /@ newshape;
ListPlot[shifted, PlotRange -> All]
ListPlot[shifted, PlotRange -> {{20, 85}, {-1, 1}}]
ListLinePlot[shifted, PlotRange -> {{40, 65}, {-0.025, 0.025}}]


The last plot hints at the amount of distortion that would be required to really superimpose the curves throughout the region.

Sensitivity

As it turns out, choosing the 50th data point of each curve worked fairly well. But what if another index had been used? We can use Manipulate to test other values of the index like this:

Manipulate[
shifted = # /. {x_, y_} :> {x, y - #[[ndx, 2]]} &  /@ newshape;
GraphicsColumn[{
ListPlot[shifted, PlotRange -> All, ImageSize -> Small],
ListLinePlot[shifted,
PlotRange -> {{40, 65}, {-0.025, 0.025}},
ImageSize -> Small]
}],
{{ndx, Length[shifted[[1]]]/5, ndx}, 1, Length[shifted[[1]]], 1}]


We can change the value of the index to see how that affects the overlay of the curves.

Toward an automated method

It may be possible to use the manipulator on several different datasets to develop a method of choosing the index that determines the amount of the shift. For instance, it may be found that 20th data point is a good choice if the curves are to overlay between x=20 and x=40.

Another strategy may be to shift the curve so that some data point near the middle of the valley between the first two peaks lies on the x-axis.

Combine PeakDetect and Position commands to find the indices for the peaks and take it from there.

PlotLegends

The questions on this site contain many good examples of using PlotLegends. If you have a some specific case that is not working for you, please post the troublesome code in a new question.

• Thank you very much Louis! Is there any way to do it automatically? For example by selecting the range of all data were I want to superimposed (e.g 40 to 65 of the x axis in this case). In other case, It can be from 20 to 40 or something like that, so I was wondering if there is a way to make it automatic?
– John
Jan 23, 2021 at 2:21
• Thanks LouisB! Can you look at the data that has two data sets? That one doesn't seem to work with the code and I am not sure how to fix it
– John
Jan 23, 2021 at 13:11