5
$\begingroup$

I'm fighting with a seemingly very simple problem:

I have two lists of data, and want to plot them with ListLinePlot. The two lists are only data-points, therefore the following code

L1 = {2222, 2500, 5456, 4000, 1000, 6000, 2000, 4000, 2200, 8000, 1800};
L2 = {4500, 6400, 4800, 2600, 2000, 2300, 1800, 2600, 3400, 4500, 2700};
ListLinePlot[{L1, L2}, PlotMarkers -> Automatic, AxesLabel -> {"phi", "Events"}]

produces a plot with x-axis from 1 to 18. However, I want the x-axis (for both lists) being an individual scale.

I know that I can do it like this:

L1 = {{10, 2222}, {40, 2500}, {100, 5456}, {120, 4000}, {130, 1000}, {170, 6000}, {172, 2000}, {174, 4000}, {176, 2200}, {177, 8000}, {180, 1800}};
ListLinePlot[{L1}, PlotMarkers -> Automatic, AxesLabel -> {"phi", "Events"}]

But if I want to have the same x-axis for both L1, L2, I would need to add the axis to both lists. Is there a simpler way?

$\endgroup$
5
$\begingroup$
L1 = {2222, 2500, 5456, 4000, 1000, 6000, 2000, 4000, 2200, 8000, 1800};
L2 = {4500, 6400, 4800, 2600, 2000, 2300, 1800, 2600, 3400, 4500, 2700};
xr = {10, 40, 100, 120, 130, 170, 172, 174, 176, 177, 180};

ListLinePlot[{Transpose[{xr, L1}], Transpose[{xr, L2}]},
 PlotMarkers -> Automatic,
 AxesLabel -> {"phi", "Events"}]

enter image description here

$\endgroup$
  • $\begingroup$ faster response and with the plot...+1:) $\endgroup$ – ubpdqn Oct 17 '14 at 11:48
5
$\begingroup$

TemporalData may be quite useful for the purpose:

Series:

L1 = {2222, 2500, 5456, 4000, 1000, 6000, 2000, 4000, 2200, 8000,  1800};
L2 = {4500, 6400, 4800, 2600, 2000, 2300, 1800, 2600, 3400, 4500,  2700}; 

Time-stamps:

ts1 = {10, 40, 100, 120, 130, 170, 172, 174, 176, 177, 180};
ts2 = ts1 + 30;

Temporal data with common time-stamps:

tda = TemporalData[{L1, L2}, {ts1}];
ListLinePlot[tda, PlotMarkers -> Automatic, AxesLabel -> {"phi", "Events"}]

enter image description here

Temporal data with individual time-stamps:

tdb = TemporalData[{L1, L2}, {{ts1}, {ts2}}];
ListLinePlot[tdb, PlotMarkers -> Automatic, AxesLabel -> {"phi", "Events"}]

enter image description here

$\endgroup$
4
$\begingroup$
xv = {10, 40, 100, 120, 130, 170, 172, 174, 176, 177, 180};
l1 = {2222, 2500, 5456, 4000, 1000, 6000, 2000, 4000, 2200, 8000, 
   1800};
l2 = {4500, 6400, 4800, 2600, 2000, 2300, 1800, 2600, 3400, 4500, 
   2700};
ListLinePlot[Transpose[{xv, #}] & /@ {l1, l2}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.