1

Matplotlib has the option to specify a edge color, e.g. How to set the border color of the dots in matplotlib's scatterplots?

In gnuplot, I work it around with

array data[500]
do for [i=1:500] {data[i]=invnorm(rand(0))}

pl data ps 2 pt 7, "" ps 2 pt 6 lc "black"

However, this requires a second loop over the data (and more duplicated typing, in particular when more complex column operations are involved). Moreover, the legend is not as intended.

How can the legend be fixed? Or are there better ways?

(E.g. for postscript terminals a solution is to parse the output, set out "| sed '/ hpt 0 360/s/ Pnt//; s,hpt.*arc fill, 2 copy & stroke LTb Circle, ' > out.ps.)

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

1 Answers1

1

You could use the plotting style with circles. Check help circles.

Code:

### "points" with outline --> with circles
reset session

set print $Data
do for [i=1:200] {
    print sprintf("%g %g", invnorm(rand(0)),invnorm(rand(0)))
}
set print

set style circle radius graph 0.01 wedge
set style fill solid 1.0 border lc "black"

plot $Data u 1:2 w circles fc "red" 
### end of code

Result:

enter image description here

Addition:

Just for fun... here is a way to plot triangles (or squares, diamonds or pentagons) with border. The simple way to plot the data twice, once with closed symbol and again with open symbol does not give the desired result (see left graph). Actually, you have to duplicate each line and plot alternating closed and open symbols (right graph). However, I haven't yet found a solution to show the symbol with border in the legend.

Code:

### triangles with border
reset session

set print $Data
    do for [i=1:100] {
        print sprintf("%g %g", invnorm(rand(0)),invnorm(rand(0)))
    }
set print

# duplicate each line
set print $Data2
    do for [i=1:|$Data|] {
        print $Data[i]
        print $Data[i]
    }
set print

set key out center top noautotitle
myPt = 9    # 5=square, 7=circle, 9=triangle up, 11=triangle down, 13=diamond, 15=pentagon
myLw = 1.5
myPs = 4
myColor(col) = int(column(col))%2 ? 0x000000 : 0xffff00
myPoint(col) = int(column(col))%2 ? myPt-1: myPt

set multiplot layout 1,2
    plot $Data u 1:2 w p pt myPt   ps myPs lc "yellow" ti "serial", \
            '' u 1:2 w p pt myPt-1 ps myPs lw myLw lc "black"
    
    plot $Data2 u 1:2:(myPoint(0)):(myColor(0)) w p pt var ps myPs lw myLw lc rgb var, \
         keyentry w p pt myPt ps myPs lc rgb 0xffff00 ti "alternating"
unset multiplot
### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72
  • `Sorry, no help for 'with circles'`. At least in v5.2.2. – Friedrich -- Слава Україні May 04 '21 at 09:02
  • Ok, in gnuplot 5.4.1 you get some help with `help with circles`. But in 5.2.2 you get nothing, only with `help circles`. Actually, in both versions you get something with `help circles`, not to mix-up with `help circle`. I will modify the answer to avoid confusion. – theozh May 04 '21 at 09:25
  • Towards a oneliner: `plot $Data u 1:2:("0.05") w circles fs solid 1. border lc "black" fc "red"`. – Friedrich -- Слава Україні May 04 '21 at 09:32
  • Squares might be possible with boxxyerror. But I guess diamonds and triangles are not possible with this solution. – Friedrich -- Слава Україні May 04 '21 at 09:35
  • @Friedrich yes, all the other pointtypes (diamonds, triangles, pentagons) will get difficult. I guess then your are back to plotting twice, i.e. filled and empty points. But to get the "real desired" result, you would have to plot filled and empty points alternating, not just all filled points and then all empty ones. Furthermore, for plotting twice you would have to play some tricks for the "correct looking" legend. – theozh May 04 '21 at 09:51