有条件地在Gnuplot中绘制多个文件

时间:2013-02-21 18:32:48

标签: gnuplot

这是这个问题的一个分支,虽然有点复杂(或似乎)。

Using Gnuplot to plot point colors conditionally

这是合约。我有两个不同的文件。一个文件具有最佳数据点,一个文件具有不可行和非最佳数据点。

文件的格式与上一个问题的格式相同,但稍后我会再次发布。

我的目标是用脉冲(可能)在一个单独的3D散点图上绘制所有内容。

想象一下,我有一个约束,说Xvalue> 18,Yvalue< 20和Z值> 65.典型范围是X = [0:22],Y = [0:500],Z = [0:85](与上一篇文章相比变化不大)。

任何不符合此标准的点都是不可行的,并且必须以灰色绘制。符合此条件的任何点,但是来自non_optimal_file.dat的要点都要用红色绘制。最后,optimal_data.dat文件中的点必须以蓝色绘制。不言而喻,这些文件中的要点必须可行。

我正在使用@ andyras的解决方案,可以解决问题的第一部分。但是当我将其他文件合并到同一个图中时,它只是将所有点都变为灰色。我重新定义了我的调色板等,但能够获得蓝色和红色的不可行和非最佳点,而不是灰色和红色。我能够用黑色绘制最佳的,但我无法使用任何其他颜色。有人可以指导我为这个问题设置调色板吗?

我用过这个:

  

设定调色板定义(0 0 0 1,1 1 0 0,2 1 0 0)#(蓝色,黄色,红色)

 >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"

数据文件的格式与前一种情况相同。我需要使用顺序为2:1:3的前三列作为X:Y:Z。

示例数据: 最佳点:

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

非最佳/不可行点:

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

我被引导为此创建一个新问题,因为它略有不同。因此分支。如果不这样做,请道歉。

1 个答案:

答案 0 :(得分:1)

好的,我想我找到了一个解决方案(对不起延迟)。

#!/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

我认为这个脚本就像你描述的那样;我大多对最佳与非最佳等问题感到困惑。我认为你的脚本不起作用的原因是你使用相同的比较器(isbig(x,y,z))试图获得三种可能的结果,但是该函数只定义了两个。我刚刚在第二个数据文件中定义了第二个比较器,它似乎工作正常。

相关问题