0
$\begingroup$

We have the following simple example

data = {{1, 1.5}, {2, 3}, {3, 5}, {4, -1}, {5, -9}, {6, 1}, {7, 10}};
L0 = ListPlot[data, Joined -> True, Axes -> False, Frame -> True, 
PlotRange -> {{1, 7}, {-10, 10}}]

enter image description here

The joined line divides the plane into two areas (upper and lower). Is there any easy way to paint, let's say green the upper area and red the lower, while the line should be still visible?

Many thanks in advance!

$\endgroup$

2 Answers 2

2
$\begingroup$
data2 = {{1, 10}, {7, 10}}; data = {{1, 1.5}, {2, 3}, {3, 
   5}, {4, -1}, {5, -9}, {6, 1}, {7, 10}}; L0 = 
 ListPlot[{data2, data}, Joined -> True, Axes -> False, Frame -> True,
   PlotRange -> {{1, 7}, {-10, 10}}, 
  Filling -> {1 -> {{2}, Green}, 2 -> {Bottom, Red}}, 
  PlotStyle -> {Automatic, {Black, Thickness[0.02]}}]

enter image description here

you can also use Show as follows:

L0 = ListPlot[{data}, Joined -> True, Axes -> False, Frame -> True, 
  PlotRange -> {{1, 7}, {-10, 10}}, Filling -> {1 -> { Bottom, Red}} ,
   PlotStyle -> {Black, Thickness[0.02]}];
 L1 =ListPlot[{data}, Joined -> True, Axes -> False, Frame -> True, 
      PlotRange -> {{1, 7}, {-10, 10}}, Filling -> {1 -> { Top, Green}} , 
      PlotStyle -> {Black, Thickness[0.02]}];
    Show[L0, L1]
$\endgroup$
1
  • $\begingroup$ The line between the two areas is not visible any more $\endgroup$
    – Vaggelis_Z
    Commented Jan 17, 2015 at 16:16
2
$\begingroup$

An alternative syntax using FillingStyle explicitly

enter image description here

data = {{1, 1.5}, {2, 3}, {3, 5}, {4, -1}, {5, -9}, {6, 1}, {7, 10}};
L0 = ListPlot[data, Joined -> True, Axes -> False, Frame -> True, 
  PlotRange -> {{1, 7}, {-10, 10}}, 
  PlotStyle -> Directive[Black, AbsoluteThickness[5]], 
  Filling -> {1 -> Top, 1 -> Bottom}, FillingStyle -> {Green, Red}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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