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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.