Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
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.

share|improve this question
1  
One question remains: how do you want to partition your data? –  Öskå Feb 13 at 19:07

3 Answers 3

up vote 2 down vote accepted
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

share|improve this answer

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

share|improve this answer

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}]
share|improve this answer
    
+1 Nice answer! –  Mike Honeychurch Feb 14 at 5:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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