如何使边缘标记颜色

时间:2021-05-04 07:47:51

标签: gnuplot

Matplotlib 可以选择指定边缘颜色,例如 How to set the border color of the dots in matplotlib's scatterplots?

在 gnuplot 中,我使用

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"

然而,这需要对数据进行第二次循环(以及更多的重复输入,尤其是在涉及更复杂的列操作时)。此外,图例并不符合预期。

如何修复图例?或者有更好的方法吗?

(例如,对于 postscript 终端,解决方案是解析输出,set out "| sed '/ hpt 0 360/s/ Pnt//; s,hpt.*arc fill, 2 copy & stroke LTb Circle, ' > out.ps。)

1 个答案:

答案 0 :(得分:1)

您可以使用绘图样式 with circles。检查help circles

代码:

### "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

结果:

enter image description here

添加:

只是为了好玩……这是一种绘制带边框的三角形(或正方形、菱形或五边形)的方法。 绘制数据两次的简单方法,一次使用封闭符号,另一次使用开放符号并没有给出所需的结果(见左图)。实际上,您必须复制每条线并绘制交替的闭合和开放符号(右图)。但是,我还没有找到在图例中显示带边框符号的解决方案。

代码:

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

结果:

enter image description here