# How can I breakdown different segment of the graph

I have constructed a graph using ListLinePlot, using the existing input data from the matrix calculation.

May I ask how can I create a different segment based on existing graph. The graph x-axis ranges from 0 to 540. I need to create three segments, based on the existing graph that I have.

So between 0 to 540, I need help in creating three segments from the existing data to 0-220, 221-421, 422 to 540. I have tried using DataRange, but the outcomes are still the same.

Appreciate your help. Thanks

• I'm having a hard time understanding what do you want to achieve. Please show some exemplary dataset, the plot, and describe in more detail what's the output you want to obtain. Commented Jan 12, 2017 at 10:53
• Thanks corey979, I have updated the question.
– ljsg
Commented Jan 13, 2017 at 1:50

## 1 Answer

lst1 = Accumulate[RandomReal[{-1, 1}, 540]];


1. Restructure your input data:

lst2 = MapIndexed[{#2[[1]], #} &, lst1];

{data1, data2, data3} = {lst2[[;; 220]], lst2[[221 ;; 421]], lst2[[422 ;;]]};

ListLinePlot[{data1, data2, data3} ]


2. Use Mesh and MeshShading:

ListLinePlot[lst1, Mesh -> {{221, 422}}, MeshShading -> {Red, Blue, Green}]


3. Use ColorFunction that specifies different colors for different values of x:

ListLinePlot[lst1, ColorFunctionScaling -> False,
ColorFunction->Function[{x, y}, Which[x <= 220, Orange, 221 <= x < 421, Cyan, True, Red]]]


4. Plot each piece separately with appropriate DataRange values and combine with Show:

ranges = {{1, 220}, {221, 421}, {422, 540}};
colors = {Red,  Green, Purple};

plots = ListLinePlot[lst1[[Span @@ #]],  DataRange -> #,
PlotStyle -> #2] & @@@ Transpose[{ranges, colors}];
Show[plots, PlotRange -> All]


5. Post-process ListLinePlot output to add different directives for different pieces:

ListLinePlot[lst1] /.
Line[x_] :> ({#, Line[x[[Span @@ #2]]]} & @@@ Transpose[{colors, ranges}])


• Thanks Kglr! It was really useful! I will give a try. Appreciate it!
– ljsg
Commented Jan 13, 2017 at 8:55