4

I have the 2 files from either of them I'll plot a point line using the following code:

set terminal postscript eps color solid font "Helvetica, 22"
set size ratio 0.625
set output "example.eps"

set key right top

plot "traffic.txt" using 1:2 title "traffic" with lp pt 7 ps 1 lc rgb "red", \
 "solar.txt" using 1:($2*100) title "solar" with lp pt 9 ps 1 lc rgb "blue"

Either line forms a region together with x axis and the regions formed by both lines overlaps. I was wondering how may I shade the overlapping parts.

Thanks!

(The files used are as follows)

File 1

1   66.660000
2   47.830000
3   39.270000
4   27.940000
5   24.990000
6   27.930000
7   32.060000
8   43.650000
9   70.470000
10   73.430000
11   87.690000
12   111.790000
13   122.170000
14   114.930000
15   111.620000
16   109.330000
17   121.370000
18   118.600000
19   132.890000
20   132.480000
21   148.360000
22   152.260000
23   140.510000
24   99.120000

File 2

1   0
2   0
3   0
4   0
5   0
6   0
7   0
8   0
9   0.121933
10  1.81455
11  2.25622
12  2.67994
13  2.87834
14  2.53149
15  1.29541
16  0.57571
17  0.0883007
18  0
19  0
20  0
21  0
22  0
23  0
24  0
beresfordt
  • 5,088
  • 10
  • 35
  • 43
Zhe Wen
  • 41
  • 1
  • 3
  • No need for shouting in ALL CAPS in the title. It's already bold and big. –  Nov 09 '13 at 07:19

1 Answers1

5

You can use the filledcurves plotting style. For that all data must be contained in one file. You can combine the files on-the-fly e.g. with paste. For a platform-independent solution with python look e.g. this answer.

With filledcurves you can also distinguish between above and below in order to use different colors:

set key right top
set autoscale xfix
set xtics 4
plot "< paste traffic.txt solar.txt" using 1:2:($4*100) with filledcurves below lc rgb "#ffaaaa" t '', \
     "" using 1:2:($4*100) with filledcurves above lc rgb "#aaaaff" t '',\
     "traffic.txt" using 1:2 title "traffic" with lp pt 7 ps 1 lc rgb "red", \
     "solar.txt" using 1:($2*100) title "solar" with lp pt 9 ps 1 lc rgb "blue"

The result with 4.6.4 is:

enter image description here

To shade only the region where the two curves overlap, you need a workardound. First shade the region between the narrower curve and the x1 axis, and then overwrite parts of that shading with white:

set autoscale xfix
set xtics 4
plot "< paste traffic.txt solar.txt" using 1:($4*100) with filledcurves x1 lc rgb "#ffaaaa" t '', \
     "" using 1:2:($4*100) with filledcurves below lc rgb "white" t '',\
     "traffic.txt" using 1:2 title "traffic" with lp pt 7 ps 1 lc rgb "red", \
     "solar.txt" using 1:($2*100) title "solar" with lp pt 9 ps 1 lc rgb "blue"

This gives:

enter image description here

Community
  • 1
  • 1
Christoph
  • 47,569
  • 8
  • 87
  • 187
  • This is cool! But what I am expecting is shading the overlapping region (the opposite to current shaded zone). Is it possible to do that? – Zhe Wen Nov 09 '13 at 19:32