2
$\begingroup$
data = { {2, 60}, {4.5, 62}, {6.5, 64}, {8, 65}, {9, 65}, {10, 
  65}, {11, 65}, {12, 67}, {13, 67}, {14, 67}, {16, 67}, {17, 
  67}, {18, 67}, {19, 65}, {20, 64}, {21, 70}, {22, 75}, {23, 
  80}, {24, 80}, {25, 82}, {26, 82}, {27, 79}, {30, 80}}

ListPlot[data, Joined -> True, 
AxesLabel -> {"T(Celcius)", "Volume Collected"}]

I want to partition the data into three pieces, and the plot produced should have the points joined with a line that corresponds to the color of the point.

$\endgroup$
  • 2
    $\begingroup$ One question remains: how do you want to partition your data? $\endgroup$ – Öskå Feb 13 '14 at 19:07
2
$\begingroup$
ListPlot[Evaluate[
  Cases[data, {a_ /; #[[1]] <= a <= #[[2]], __}] & /@ 
   Partition[{0, 10, 20, 30}, 2, 1]], Joined -> True, 
 PlotStyle -> Directive[Thick], 
 AxesLabel -> {"T(Celcius)", "Volume Collected"}]

enter image description here

$\endgroup$
6
$\begingroup$

You could use ColorFunction option . The following colors plot by paritioning of x-axis. You could choose your own function:

ListPlot[data, Joined -> True, 
 ColorFunction -> 
  Function[{x, y}, 
   Which[0 < x < 10, Red, 10 <= x < 20, Green, x >= 20, Blue]], 
 ColorFunctionScaling -> False, Mesh -> 10, MeshStyle -> None]

enter image description here

An alternative for partitioning x-values using MeshShading:

ListPlot[data, Joined -> True, Mesh -> {{10, 20}}, 
 MeshShading -> {Red, Green, Blue}]
$\endgroup$
4
$\begingroup$

You haven't said how to partition the data but to automate on the basis of the length of the list you can do this:

segment = Ceiling[Length[data]/3];

ListPlot[Partition[data, segment+1, segment, 1, {}], Joined -> True, 
 AxesLabel -> {"T(Celcius)", "Volume Collected"}]

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.