Max 最多绘制两个绘图
我有一个数据文件,其中的一些点如下所示(请注意,缺少一些值): 我想将这些数据绘制成这样的图形(请注意,粉色线始终是其他两条线的最大值): 为了做到这一点,我有以下gnuplot代码,它适用于除粉红线以外的所有代码:Max 最多绘制两个绘图,max,gnuplot,Max,Gnuplot,我有一个数据文件,其中的一些点如下所示(请注意,缺少一些值): 我想将这些数据绘制成这样的图形(请注意,粉色线始终是其他两条线的最大值): 为了做到这一点,我有以下gnuplot代码,它适用于除粉红线以外的所有代码: gnuplot> max(x,y) = (x>y) ? x : y gnuplot> plot "dataset1" using 1:2 title "A" with lines lc rgbcolor "black" lw 4, \ >"dataset1
gnuplot> max(x,y) = (x>y) ? x : y
gnuplot> plot "dataset1" using 1:2 title "A" with lines lc rgbcolor "black" lw 4, \
>"dataset1" using 1:3 title "1-A" with lines lc rgbcolor "blue" lw 4, \
>"dataset1" using 1:(max($2,$3)) title "Fuzzy(A)" with lines lc rgbcolor "purple" lw 4
但是,这将生成以下图形(请注意,紫色线与前一张图像中的粉色线不同):
我如何才能生成一个看起来像第一个图像的图形,而不是我所拥有的图像呢?原因有两个:
内进行计算,空的“字段”将被视为丢失的数据。如果两个点之间有一个“缺失”点,则它们仍然用一条线连接。如果之间的点未定义(当计算时),则其他两个点不连接。最简单的例子是:
set yrange[-0.1:1.1]
set multiplot layout 2,1
plot 'dataset1' using 1:2 with lines
plot 'dataset1' using 1:($2) with lines
unset multiplot
因此,必须使用外部工具筛选数据,以便正确绘制数据(另请参见):
awk
的变量,它同时进行过滤(仅使用具有三个字段的行(if(NF==3)
并跳过描述中的第一行),计算交点并将其添加到输出:
max(x,y) = (x>y) ? x : y
plot "dataset1" using 1:2 title "A" with lines lc rgbcolor "black" lt -1 lw 4, \
"dataset1" using 1:3 title "1-A" with lines lc rgbcolor "blue" lt -1 lw 4, \
"< awk 'BEGIN { prevX = prevA = prevN = currX = currA = currN = -1 } \
{ if (NF == 3 && NR > 1) { \
if (currA != -1) { prevA = currA; prevN = currN; prevX = currX } \
currX = $1; currA = $2; currN = $3; \
if ((prevA != -1) && (prevA != currA)) { \
print 0.5*(currX + prevX), 0.5*(currA+prevA), 0.5*(currN+prevN); \
}\
print \
}\
}' dataset1" \
using 1:(max($2,$3)) title "Fuzzy(A)" with lines lc rgbcolor "purple" lt 2 lw 4
和4.6.4我得到以下结果:
非常感谢。但是我必须问一下(因为我根本不知道任何
awk
——我非常awk
那样):我忍不住注意到A
和1-A
的曲线图具有彼此相反的斜率。您的解决方案是否仅适用于此类对称曲线图,还是也适用于非对称曲线图?@inspectorG4dget是的,这仅适用于A
与1-A
曲线图,但这不应该是一个问题em概括了它。
max(x,y) = (x>y) ? x : y
plot "dataset1" using 1:2 title "A" with lines lc rgbcolor "black" lt -1 lw 4, \
"dataset1" using 1:3 title "1-A" with lines lc rgbcolor "blue" lt -1 lw 4, \
"< awk 'BEGIN { prevX = prevA = prevN = currX = currA = currN = -1 } \
{ if (NF == 3 && NR > 1) { \
if (currA != -1) { prevA = currA; prevN = currN; prevX = currX } \
currX = $1; currA = $2; currN = $3; \
if ((prevA != -1) && (prevA != currA)) { \
print 0.5*(currX + prevX), 0.5*(currA+prevA), 0.5*(currN+prevN); \
}\
print \
}\
}' dataset1" \
using 1:(max($2,$3)) title "Fuzzy(A)" with lines lc rgbcolor "purple" lt 2 lw 4
set termoption dashed
set key above right
set autoscale fix
set offset 0,0,0.1,0