点颜色取决于字符串列值

时间:2018-06-06 17:32:01

标签: gnuplot

我想用红色或绿色的点绘制简单的2D点图,其中颜色由第三个字符串列确定。这个没有编译:

plot "data.txt" using 1:2:3 with points lc rgbcolor (stringcolumn(4) eq "B" ? "green" : "red")
抱怨:

stringcolumn() called from invalid context

数据如下所示:

1,2,"A"
2,3,"A"
3,1,"B"
4,2,"A"

怎么做?

1 个答案:

答案 0 :(得分:2)

您可以通过为每种颜色指定线型编号,然后将第3列评估为其中一个数字来完成此操作。例如:

set linetype 1 lc 'green'
set linetype 2 lc 'red'
plot "data.txt" using 1:2:(stringcolumn(3) eq "B"?1:2) with points lc variable

请注意,您的数据列必须用空格分隔,而不是用逗号分隔。

相关问题