1
$\begingroup$

Suppose I have the following data:

x = Range[15];
y1 = N[RandomInteger[100, 15]/100];
y2 =  N[RandomInteger[100, 15]/100];
y3 =  N[RandomInteger[100, 15]/100];

Now, I wish to plot values 1 to 5 of x against values 1 to 5 of y1, values 6 to 10 of x against 6 to 10 of y2, and values 11 to 15 of x against 11 to 15 of y3. Moreover, I wish to show the plots on the same chart, showing the entire range of x.

How is that done? Note that the range of 5 data points at a time was just an example. The ranges in my actual problem are varied, but never overlapping.

$\endgroup$
3
$\begingroup$
x = Range[15];
y1 = N[RandomInteger[100, 15]/100];
y2 = N[RandomInteger[100, 15]/100];
y3 = N[RandomInteger[100, 15]/100];

ListLinePlot[{
  Transpose[{x, y1}][[1 ;; 5]],
  Transpose[{x, y2}][[6 ;; 10]],
  Transpose[{x, y3}][[11 ;; 15]]
  }]

enter image description here

$\endgroup$
2
$\begingroup$

Would something like this work for you?

x = Range[15];
y1 = N[RandomInteger[100, 15]/100];
y2 = N[RandomInteger[100, 15]/100];
y3 = N[RandomInteger[100, 15]/100];
cutoffs = {1, 5, 6, 10, 11, 15};
ListLinePlot[
  Table[
    {x, y1, y2, y3}\[Transpose][[cutoffs[[2 i - 1]] ;; cutoffs[[2 i]], {1, i + 1}]], 
    {i, 3}
  ]
]

Plot of multiple functions of x.

$\endgroup$
1
$\begingroup$

You can also use TemporalData as follows:

intervals = {{1, 5}, {6, 10}, {11, 15}};
td = TemporalData[{y1, y2, y3}, {x}];
parts = MapIndexed[td["Part", #2[[1]], #] &, intervals];
ListLinePlot[parts, GridLines -> {Flatten @ intervals, None}, Filling -> Bottom]

enter image description here

intervals2 = {{1, 6}, {3, 12}, {7, 15}};
ListLinePlot[MapIndexed[td["Part", #2[[1]], #] &, intervals2], 
 Filling -> {1 -> Bottom , 2 -> 1, 3 -> Bottom}, 
 GridLines -> {Flatten @ intervals2, None}]

enter image description here

$\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.