Search code examples
gnuplot

gnuplot: how to set the different fill and border colors for `with points`?


I would like to achieve a similar effect in gnuplot.

effect

Here is what I tried:

unset key
set style line 11 lc rgb '#808080' lt 1
set border 3 ls 11
set tics nomirror
set grid

set style line 1 lc rgb '#808080' pt 9 ps 3
set style line 2 lc rgb '#808080' pt 20 ps 3
set style line 3 lc rgb '#BD3828' pt 7 ps 3

set yrange [4:9]
$data << EOD
5   5.1
5.3 6.8
6   6
EOD

$data2 << EOD
5 5
7 7
8 6
EOD

$data3 << EOD
5.5 7
6 6
7 7.1
EOD

plot $data u 1:2 w points ls 1, $data2 u 1:2 w points ls 2, \
$data3 u 1:2 w points ls 3

enter image description here

As we can see, points can be overlapped. Then how can we darken the overlap areas?


A possible solution is to set transparency (e.g., lc rgb '#80808080'), but it will also make both border and filling transparent. So how to set the different fill and border colors for with points?

Another solution is to use set object, but we need to do more work to read data from files.


Solution

  • I think the closest you could come to what you describe is to draw the points in two passes.

    First pass: draw using a point type that produces only the outlines (point types N = 4 6 8 10 12 ...).

    Second pass: draw using the corresponding point type N+1 that produces only the interior, using the same color but adding an alpha channel value to make it partially transparent.

    set print $RAND1
    do for [i = 1:50] { print rand(0), rand(0) }
    unset print
    set print $RAND2
    do for [i = 1:50] { print rand(0), rand(0) }
    unset print
    
    set pointsize 4
    
    plot $RAND1 with points pt  8 lc rgb "#00b8860b", \
             '' with points pt  9 lc rgb "#AAb8860b", \
         $RAND2 with points pt  6 lc rgb "#00c04000", \
             '' with points pt  7 lc rgb "#AAc04000"
    

    enter image description here