6

I have a file with four columns of data. I am using just the first three to plot a 3D plot and do not need the fourth one right now.

I want to know how to change the color of a point if it meets certain conditions. For example, if a point's values (x,y,z) are greater than (16,400,65), I want to plot it in grey. If they are lesser than that, I want to use red.

I am trying to use awk for the same and it plots just two points in a different color. Here is my code.

gnuplot>splot "< awk '{if( ($2 > \"16\") || ($1 > \"400\") || ($3 > \"65\"))  print}'                                       
./8_77_non_pareto_data.dat " u 2:1:3 w p pt 8 lc rgb "grey", \
"< awk '{if( ($2 < \"16\") || ($1 < \"400\") || ($3 < \"65\"))  print}' 
./8_77_non_pareto_data.dat " u 2:1:3 w p pt 8 lc rgb "red", \
"./8_77_pareto_data.dat" u 2:1:3 w i lt 1 lc rgb "blue" t "Pareto points"

My data file looks like this:

48      15.057599573464184      68      361
93      14.950459657063462      73      361
48      14.065204842090914      69      361
280     13.16320458043516       69      361
120     15.05281009307949       66      361
48      15.133322961840786      59      361
48      16.161631503473544      73      361
470     17.763180586730847      77      361

X axis ranges from 6 to 22.

Y-axis ranges from 0 to 500.

Z-axis ranges from 35 to 85.

I would like to visualize this as having a bounding box around (16,400,65) in a three dimensional way. Anything inside the box is red, anything outside it is grey.

Hope someone can help me here.

P.S : The blue points are printing just fine and though the sample data here does not show some conditions being met, there are points that meet that condition. I did not post the whole file here.

John_West
  • 2,239
  • 4
  • 24
  • 44
adwaraki
  • 342
  • 1
  • 5
  • 14

1 Answers1

5

You can reduce the awk effort somewhat and do it in pure gnuplot by defining a simple function:

#!/usr/bin/env gnuplot

set terminal png set output 'test.png'

bigx = 16; bigy = 400; bigz = 65

isbig(x,y,z) = (x > bigx || y > bigy || z > bigz) ? 1 : 0

set palette defined (0 0.5 0.5 0.5, 1 1 0 0) # (grey, red)

unset colorbox
set xrange [0:20]; set yrange [0:500]; set zrange [0:100]

splot 'data.dat' using 2:1:3:(isbig($2,$1,$3)) with points pt 7 palette notitle, \
      '' using (1e6):1:1 with points pt 7 lc rgb '#888888' title 'in box', \
      '' using (1e6):1:1 with points pt 7 lc rgb 'red' title 'not in box'

(The lines setting the range and unsetting the colorbox, as well as the two extra plot commands, are just to make things pretty in my opinion. It gives a key which describes what the two colors mean without the distracting colorbox.)

enter image description here

andyras
  • 15,542
  • 6
  • 55
  • 77
  • Another quick question. Suppose I have two files, both like the one described above. One holds optimality data and the one that I have showed you holds non-optimal/sub-optimal data. My goal is to plot both on the same plot, albeit the non-optimal ones that fall outside the bounding box in grey, the sub-optimal ones inside the box in red points (these two are in one file) and the optimal points in blue impulses (these are in the other file). Right now, if I try to plot the optimal points on the same plot, all the points change to grey. Any pointers please? – adwaraki Feb 21 '13 at 13:07
  • It sounds like you're having a slightly different issue here, and I recommend you post it as a new question, with example script and data attached that reproduce the problem. Right now I suspect the palette is the issue, but I'm not sure. Also it looks like you're new to SO, so I'd like to mention that if you like an answer it's common courtesy to upvote as well as accept it :) – andyras Feb 21 '13 at 13:57
  • I will do that. Thanks. But when I try to up-vote it (which I tried yesterday already :) ), it says a min of 15 rep points are required to up-vote. How do I do that? – adwaraki Feb 21 '13 at 15:54
  • There are several ways to gain reputation (http://stackoverflow.com/faq#reputation), but in general just keep asking and answering good questions! – andyras Feb 21 '13 at 16:57
  • Can you please elaborate on the last two lines of your example? Rather, can I use points for out of the box and impulses for in the box? Right now, I think the first line of splot is dictating my drawing style. Is there another way to do it? – adwaraki Feb 21 '13 at 23:47