0
votes

This is an offshoot of this question here, albeit a bit more complicated (or it seems).

Using Gnuplot to plot point colors conditionally

Here is the deal. I have two different files. One file has optimal data points and one file has infeasible and non-optimal data points.

The files are in the same format as in the previous question, but I will post them again later.

My aim to plot everything on one single 3D scatter plot with impulses (probably).

Imagine, I have a constraints that say Xvalue > 18, Yvalue < 20 and Zvalue > 65. Typical ranges are X=[0:22], Y=[0:500], Z=[0:85] (small changes from the last post).

Any points that do not meet this criteria are infeasible and HAVE to be plotted in grey. Any points that meet this criteria but are from the non_optimal_file.dat HAVE to be plotted in red. And finally, the points that are in the optimal_data.dat file have to plotted in blue. It goes without saying that the points in those files have to be feasible.

I was using @andyras's solution and could work out the first part of the problem. But when I incorporated the other file into the same plot, it just turned all the points grey. I redefined my palette etc., but was able to get the infeasible and non-optimal points in blue and red, not grey and red. I was able to plot the optimal ones in black, but I am not able to use any other colors. Can someone please guide me with setting the palette for this problem?

I used this:

set palette defined (0 0 0 1, 1 1 0 0, 2 1 0 0) # (blue, yellow, red)

 >splot 'data.dat' using 2:1:3:(isbig($2,$1,$3)) with points pt 8 palette notitle, \
 >      '' using (1e6):1:1 with points pt 8 lc rgb 'blue' title 'Optimal non-pareto', \
 >      '' using (1e6):1:1 with points pt 8 lc rgb 'red' title 'Non-optimal',    
 "./8_77_pareto_data.dat" u 2:1:3:(isbig($2,$1,$3)) w i lt 3 lc rgb 'black' t "Optimal 
 pareto"

The data file is in the same format as the previous case. I need to use the first three columns in the order 2:1:3 as X:Y:Z.

Sample data: Optimal points:

20      10.078509647223639      50      172
46      10.395137748213685      43      18
34      10.1846571593967        33      18
74      11.054241806019         42      18
34      11.472806910917914      30      92

Non-optimal/infeasible points:

20      9.835854999471227       42      35
20      11.901179073913957      44      35
20      12.204287402540535      51      35
255     15.216006917180689      66      172
20      11.651167171495924      52      172
20      11.89284904845455       48      172

I was guided to create a new question for this since it was slightly different. And hence the offshoot. Apologies if it was not to be done.

1

1 Answers

1
votes

OK, I think I figured out a solution (sorry for the delay).

#!/usr/bin/env gnuplot

set terminal png
set output 'test.png'

# cutoffs for non-optimal points
bigx = 16; bigy = 400; bigz = 65
# big value to shift dummy points off of plot
shift = 1e6

# conditional for non-pareto
isbig(x,y,z) = (x > bigx || y > bigy || z > bigz) ? 1 : 0
# conditional for pareto
isbig2(x,y,z) = (x > bigx || y > bigy || z > bigz) ? 0 : 2

set palette defined (0 0.5 0.5 0.5,\
                     1 1.0 0.0 0.0,\
                     2 0.0 0.0 1.0) # (grey, red, blue)

unset colorbox

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

# plot commands for points use dummy points just to make key
# this is because there are multiple types of points coming from one file
splot 'data.dat' using 2:1:3:(isbig($2,$1,$3)) with points pt 7 palette notitle, \
      'optimal.dat' using 2:1:3:(isbig2($2,$1,$3)) with points pt 7 palette notitle, \
      '' using (shift):(1):(1) with points pt 7 lc rgb 'blue' title 'optimal non-pareto', \
      '' using (shift):(1):(1) with points pt 7 lc rgb '#888888' title 'optimal pareto', \
      '' using (shift):(1):(1) with points pt 7 lc rgb 'red' title 'non-optimal'

enter image description here

I think this script does as you described; I mostly got confused about optimal vs. non-optimal, etc. I think the reason your script did not work is that you were using the same comparator (isbig(x,y,z)) to try to have three possible outcomes, but the function only defines two. I just defined a second comparator to use on the second data file, and it seems to work fine.