Change point color based on column value for multiple gnuplot data blocks
My question is very similar to this one , from which I was able to learn a lot. However, I am working with multiple blocks of data, for example:
1 2 3
4 5 6
7 8 0
4 3 0
4 5 7
2 3 0
4 5 0
5 6 7
and I draw them like this:
plot "file.txt" index 0 u 1:2 w points pt 1,\
"file.txt" index 1 u 1:2 w points pt 2
which creates 2 different sets of points, each with a different color. Now my goal is to change this script so that if the 3rd column of data is 0, the point color will turn black. I would like the other dots to remain in the colors they currently have (i.e. different from each other). I did this:
set palette model RGB defined ( 0 'black', 1 'green' )
unset colorbox
plot file index 0 u 1:2:( $3 == 0 ? 0 : 1 ) w points pt 1 palette,\
file index 1 u 1:2:( $3 == 0 ? 0 : 1 ) w points pt 2 palette
This does exactly what I want, except that both sets are now displayed in green. Is there a way to paint black as desired, but also make each index a different color?
source to share
This is a special "variable" color for:
plot 'test.dat' i 0 u 1:2:($3 == 0? 0:1) w p pt 1 lc variable,\
'test.dat' i 1 u 1:2:($3 == 0? 0:2) w p pt 2 lc variable
variable
in this context says to use the color of any "style index" in the third column. I am setting filters on a third column variable which converts the third column to a constant (1 or 2) if the data in that column is not 0.
Another, less direct approach (which works since you use dots):
plot 'test.dat' i 0 u 1:($3 == 0? 1/0: $2) w p pt 1 lc rgb "red",\
'test.dat' i 0 u 1:($3 == 0? $2:1/0) w p pt 1 lc rgb "black,\
'test.dat' i 1 u 1:($3 == 0? 1/0: $2) w p pt 1 lc rgb "green",\
'test.dat' i 1 u 1:($3 == 0? $2:1/0) w p pt 1 lc rgb "black,\
source to share