3

My question is very similar to this one, from which I was able to learn a lot. However, I am working with multiple data blocks, like this:

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 am plotting 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 a different color. Now, my goal is to modify this script so that if the 3rd data column is 0, the color of the point will become black. I would like for the other points to remain the colors that they currently are though (meaning different from one another). I have done 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 of course both sets are now plotted in green. Is there any way to plot the black ones as desired, but also make each index a different color?

Community
  • 1
  • 1
whatsherface
  • 313
  • 2
  • 8
  • 21

2 Answers2

3

This is what the special "variable" color is 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 whatever "style index" was given in the third column. I set filters on the 3rd column variable which transforms the third column into a constant (1 or 2) if the data in that column isn't 0.

Another, less direct approach (which works since you're using points) is:

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,\
mgilson
  • 300,191
  • 65
  • 633
  • 696
  • I have a follow-up question on this if that is ok. Let me know if I should post it as a separate question. I am now plotting things either red, green, or black by referencing the indices 0, 1, and 2. My new question is, can I plot everything whose 3rd column has non-zero value with a color gradient (using something like set palette rgbformulae 33,13,10) and then if the 3rd column has value zero, plot it in black? – whatsherface Oct 20 '12 at 23:17
  • @whatsherface -- If I understand you correctly, that should be possible by just combining my answer and the answer by andyras – mgilson Oct 21 '12 at 00:55
  • I believe that will work to give me discrete colors, but I would like to use a gradient based on the data of the 3rd column. As I understand it, ($8 == 0.0 ? 0 : 1) means: if the 8th column is zero, plot the color that is referenced by "0" (black), if not, plot the color that is referenced by "1". What I need is: if zero, plot black, if not, use the gradient rgbformulae 33,13,10. Can I reference a color gradient using a single index? – whatsherface Oct 21 '12 at 04:23
  • @whatsherface -- Post a new question I think. I'm pretty sure I can answer this one, but doing it in comments won't do it justice. (and I bet you can give a better explanation outside of comments as well). – mgilson Oct 22 '12 at 02:49
2

It should work to define an extra point in the palette:

set palette model RGB defined ( 0 'black', 1 'green', 2 'red')
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 : 2 ) w points pt 2 palette

enter image description here

andyras
  • 15,542
  • 6
  • 55
  • 77