在 Gnuplot 中,如何在第三列为零时使点为一种颜色,否则为另一种颜色? [英] How to make points one color when a third column equals zero, and another color otherwise, in Gnuplot?
问题描述
我需要根据一列中的颜色改变一行值的点颜色.数据:
I need to vary the point color for a row of values based on the color in one column. The data:
# x y z
1, 3, 0
1, 5, 6
3, 5, 2
4, 5, 0
如果列为零,颜色应该是一个值,如果第三列中的值不为零,则颜色应该是不同的.
The color should be one value if the column is zero and a different color if the value in the third column is non-zero.
所以,我假设:
plot "./file.dat" u 1:2:3 with points palette
在此处找到:https://stackoverflow.com/a/4115001 不太好用.
as found here: https://stackoverflow.com/a/4115001 will not quite work.
在上面的示例数据中,gnuplot 命令提供了三种不同的颜色,而不是我正在寻找的两种颜色.
In the above example data, that gnuplot command provides three different colors instead of the two I'm looking for.
推荐答案
这可能接近你想要的:
set palette model RGB defined ( 0 'red', 1 'green' )
plot[0:5][0:6] "file.dat" u 1:2:( $3 == 0 ? 0 : 1 ) with points palette
您可以更进一步,消除噪音":
You could go one step further and remove the "noise":
unset key
unset colorbox
plot[0:5][0:6] "file.dat" u 1:2:( $3 == 0 ? 0 : 1 ) with points pt 7 ps 3 palette
如果只有零和非零之间的区别很重要.
if only the differentiation between zero and non-zero matters.
这篇关于在 Gnuplot 中,如何在第三列为零时使点为一种颜色,否则为另一种颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!