且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

gnuplot:在一列中用基于颜色的值绘制点

更新时间:2022-12-27 14:53:32

A way how you could do that is by using awk.

Using a data file Data.csv:

5.4452 4.6816 blue
1.2079 9.4082 red
7.4732 6.5507 red
2.3329 8.2996 red
3.4535 2.1937 green
1.7909 2.5173 green
2.5383 7.9700 blue

and this script:

set pointsize 3
plot "< awk '{if($3 == \"red\") print}' Data.csv" u 1:2 t "red" w p pt 2, \
     "< awk '{if($3 == \"green\") print}' Data.csv" u 1:2 t "green" w p pt 2, \
     "< awk '{if($3 == \"blue\") print}' Data.csv" u 1:2 t "blue" w p pt 2

you get this plot:

What awk does is simply check the third parameter of the data file and only print the line if it has some value: like red or blue.

You would also get rid of the palette with the gradient.

The script could be further improved by using gnuplot iterations.