如何根据gnuplot中的数据更改点类型

How to change the point type based on the data in gnuplot

我正在尝试在 gnuplot 中绘制股市数据。所以我的问题是,我想绘制一个向上的三角形,以防我以该价格买入,并绘制一个向下的三角形,以防我以该价格卖出。但我不确定如何将变量作为参数传递给 pointtype 关键字

10-06-2021 2729.05 1
09-06-2021 2766.20 0
08-06-2021 2765.00 1
07-06-2021 2750.25 1
04-06-2021 2767.45 0
03-06-2021 2680.20 -1
02-06-2021 2645.55 -1
01-06-2021 2610.00 1
31-05-2021 2638.45 -1
28-05-2021 2630.00 0
27-05-2021 2649.00 0

这是一个示例文件,在第三列中,1 表示买入信号(我想用上升三角形表示),0 表示卖出信号(我想用下降三角形表示)和-1 表示没有 buy/sell 信号(我想用圆圈表示)

目前我只使用以下命令绘制股价数据

plot "demo.csv" using 1:2 with linespoints linecolor 11 pointtype 15

也许是这样的?此外还有不同的颜色。 请检查 help pointtype variable。如果您希望线条为单一颜色,例如“黑色”,您可能需要分别绘制 with pointswith lines.

代码:

### variable pointtype and color
reset session

$Data <<EOD
10-06-2021 2729.05 1
09-06-2021 2766.20 0
08-06-2021 2765.00 1
07-06-2021 2750.25 1
04-06-2021 2767.45 0
03-06-2021 2680.20 -1
02-06-2021 2645.55 -1
01-06-2021 2610.00 1
31-05-2021 2638.45 -1
28-05-2021 2630.00 0
27-05-2021 2649.00 0
EOD

myTimeFmt = "%d-%m-%Y"
set format x "%d-%m\n%Y" time 
myPt(col)    = column(col)==1 ? 9 : column(col)==0 ? 11 : 7
myColor(col) = column(col)==1 ? 0x00ff00 : column(col)==0 ? 0xff0000 : 0xcccccc
unset key
set grid x,y

plot $Data u (timecolumn(1,myTimeFmt)):2:(myPt(3)):(myColor(3)) w lp ps 3 pt var lc rgb var
### end of code

结果: