Gnuplot使用调色板填充曲线

Gnuplot使用调色板填充曲线,plot,gnuplot,palette,Plot,Gnuplot,Palette,我一直在尝试更改gnuplot中filledcurves选项的fillstyle,以便填充颜色表示二维绘图上两条曲线之间的差异。我认为这是“上面/下面的填充曲线”选项的延伸,即不只是有两种颜色代表上面或下面,而是有一个颜色范围或调色板 下面是一个我想使用上/下填充曲线样式从数据文件生成的绘图示例。表示两条曲线之间y差的色条非常有用 我试图通过在using命令中添加第四列来实现这一点,即 plot 'data.txt' using 1:2:3:($3-$2) with filledcurves

我一直在尝试更改gnuplot中filledcurves选项的fillstyle,以便填充颜色表示二维绘图上两条曲线之间的差异。我认为这是“上面/下面的填充曲线”选项的延伸,即不只是有两种颜色代表上面或下面,而是有一个颜色范围或调色板

下面是一个我想使用上/下填充曲线样式从数据文件生成的绘图示例。表示两条曲线之间y差的色条非常有用

我试图通过在using命令中添加第四列来实现这一点,即

plot 'data.txt' using 1:2:3:($3-$2) with filledcurves fs palette

但是
填充曲线
似乎不接受第四列。。。我也考虑过尝试使用rgb变量,但这似乎也不起作用。

诀窍是画线,然后在它们之间填充
填充曲线。以下是如何做到这一点(基于以下内容):

输出如下所示:

数据文件包含以下伪值(类似于第二个图形):


我正在使用gnuplot的补丁,允许对填充曲线使用
linecolor rgb变量
。然后可以使用以下gnuplot代码:

max_color=1
# for a datafile one could extract the maximum diffference with e.g.
# stats 'hotcold.dat' using 1:($3-$2)
# max_color = (abs(STATS_min_y) > abs(STATS_max_y)) ? abs(STATS_min_y) : abs(STATS_max_y)

red(val) = (val < 0 ? abs(1+val/max_color) : 1)
green(val) = (1 - abs(val)/max_color)
blue(val) = red(-val)
rgb(val) = 65536*int(255*red(val)) + 256*int(255*green(val)) + int(255*blue(val))

set yrange[0:1]
set xrange[400:2500]
set samples 200

fhot(x) = 0.1*exp(-((x-400)/200)**2) + 0.8*exp(-((x-2000)/300)**2)
fcold(x) = 0.25*exp(-((x-700)/100)**6)+ 0.4 - (2e-4*(x-2500))**2
plot '+' using 1:(fhot($1)):(fcold($1)):(rgb(fhot($1)-fcold($1))) with filledcurves lc rgb var t '',\
     '' using 1:(fhot($1)) with lines lw 4 lc rgb rgb(max_color) t 'Hot',\
     '' using 1:(fcold($1)) with lines lw 4 lc rgb rgb(-max_color) t 'Cold'
max\u color=1
#对于数据文件,可以使用以下方法提取最大差异:。
#使用1:($3-$2)统计“hotcold.dat”
#最大颜色=(abs(统计最小值)>abs(统计最大值))?abs(统计最小值):abs(统计最大值)
红色(val)=(val<0?绝对值(1+val/max_颜色):1)
绿色(val)=(1-绝对值(val)/最大颜色)
蓝色(val)=红色(-val)
rgb(val)=65536*int(255*red(val))+256*int(255*green(val))+int(255*blue(val))
设置Y范围[0:1]
设置X范围[400:2500]
设置样本200个
fhot(x)=0.1*exp(-(x-400)/200)**2)+0.8*exp(-(x-2000)/300)**2
fcold(x)=0.25*exp(-(x-700)/100)**6)+0.4-(2e-4*(x-2500))**2
使用1:(fhot($1)):(fcold($1)):(rgb(fhot($1)-fcold($1)))和填充曲线lc rgb var t''绘制“+”\
“”使用1:(fhot($1))和行lw 4 lc rgb rgb(最大颜色)t'Hot'\
“”使用1:(fcold($1))和行lw 4 lc rgb rgb(-max_color)t'Cold'
这就产生了这样的结果:


我还没有提交补丁,因为我不知道我是否正确理解了这个问题,也不知道我是否涵盖了所有案例。因此,可能需要进行一些微调。

尝试使用填充直方图

set style fill solid 1.0
plot \
 datafile u 1:2:3 lt palette w boxes,\
 datafile u 1:2:3 lt palette lw 2 w l
第3列根据调色板设置定义颜色填充颜色,第1列和第2列定义数据点。您还可以使用背景颜色直方图清除图形下的零件


我想添加图像,但我不能,因为声誉不好。

AFAIK,这仍然没有在
gnuplot
中实现。但是,可以通过叠加多条透明填充曲线来解决脏(*)问题

例如:

max\u color=1
最大差值=0.5
N_col=6
TRSP=“E0”
HOTCOL=“FF0000”
COLDCOL=“0000FF”
RGBA_HOT=“#”。.TRSP.HOTCOL
RGBA_COLD=“#”
RGB_HOT=“#”
RGB_COLD=“#”
#红色(val)=(val<0?绝对值(1+val/max_颜色):1)
#绿色(val)=(1-绝对值(val)/最大颜色)
#蓝色(val)=红色(-val)
#rgb(val)=65536*int(255*red(val))+256*int(255*green(val))+int(255*blue(val))
fhot(x)=0.1*exp(-(x-400)/200)**2)+0.8*exp(-(x-2000)/300)**2
fcold(x)=0.25*exp(-(x-700)/100)**6)+0.4-(2e-4*(x-2500))**2
使用((fhot($1)-fcold($1))/max_diff*N_col>thr)$1:1/0:(fhot($1)):(fcold($1))为[thr=0:N_col]“+”绘制[400:2600],(fhot($1)),带有填充曲线lc rgb RGBA_热标题“”\
对于[thr=0:N列]“+”使用(((fhot($1)-fcold($1))/max_diff*N_col>thr)?$1:1/0:(fhot($1)):(fcold($1))和填充曲线lc rgb RGBA_冷标题“”\
“”使用1:(fhot($1))和lw 4 lc rgb rgb_HOT t t'HOT'行\
“”使用1:(fcold($1))和行lw 4 lc rgb rgb_COLD t'COLD'
调整
N_col
TRSP
以更改渐变:覆盖的填充曲线数和每个曲线的透明度(更多曲线意味着更接近最大透明度
FE


(*)如果要绘制的信息是一个离散变量,例如给定横坐标下可用的数据集数量,那么这就不那么脏了。

另一个棘手的解决方法:而不是使用粗垂直矢量线的
填充曲线

当您具有示例中的函数或x中的等距数据时,这将起作用。 如果x中没有等距数据,则必须进行插值。 不幸的是,gnuplot没有插值或重采样功能。您可以使用外部工具来完成此操作,也可以使用gnuplot来完成此操作,gnuplot变得有点长,请参见此处:

为了获得好看的颜色渐变,您必须调整图形/画布大小、采样和/或线宽,以找到消除间隙、悬垂或锯齿的最佳方法。 太薄(
lw 1
)和太厚(
lw 8
)都不好。在下面的示例中,
lw 3
似乎是一个合理的值。也许有更多的方法可以进一步优化

下面的示例使用了@Christoph的代码,稍作修改

代码:

max_color=1
# for a datafile one could extract the maximum diffference with e.g.
# stats 'hotcold.dat' using 1:($3-$2)
# max_color = (abs(STATS_min_y) > abs(STATS_max_y)) ? abs(STATS_min_y) : abs(STATS_max_y)

red(val) = (val < 0 ? abs(1+val/max_color) : 1)
green(val) = (1 - abs(val)/max_color)
blue(val) = red(-val)
rgb(val) = 65536*int(255*red(val)) + 256*int(255*green(val)) + int(255*blue(val))

set yrange[0:1]
set xrange[400:2500]
set samples 200

fhot(x) = 0.1*exp(-((x-400)/200)**2) + 0.8*exp(-((x-2000)/300)**2)
fcold(x) = 0.25*exp(-((x-700)/100)**6)+ 0.4 - (2e-4*(x-2500))**2

plot \
     '+' using 1:(fhot($1)):(0):(fcold($1)-fhot($1)):(rgb(fhot($1)-fcold($1))) with vectors nohead lw 3 lc rgb var t '',\
     '' using 1:(fhot($1)) with lines lw 4 lc rgb rgb(max_color) t 'Hot',\
     '' using 1:(fcold($1)) with lines lw 4 lc rgb rgb(-max_color) t 'Cold'
     
max\u color=1
#对于数据文件,可以使用以下方法提取最大差异:。
#使用1:($3-$2)统计“hotcold.dat”
#最大颜色=(abs(统计最小值)>abs(统计最大值))?abs(统计最小值):abs(统计最大值)
红色(val)=(val<0?绝对值(1+val/max_颜色):1)
绿色(val)=(1-绝对值(val)/最大颜色)
蓝色(val)=红色(-val)
rgb(val)=65536*int(255*red(val))+256*int(255*green(val))+int(255*blue(val))
设置Y范围[0:1]
设置X范围[400:2500]
设置样本200个
fhot(x)=0.1*exp(-(x-400)/200)**2)+0.8*exp(-(x-2000)/300)**2
fcold(x)=0.25*exp(-(x-700)/100)**6)+0.4-(2e-4*(x-2500))**2
密谋\
“+”使用1:(fhot($1)):(0):(fcold($1)-fhot($1)):(rgb(fhot($1)-fcold($1)))和向量nohead lw 3 lc rgb var t'\
“”使用1:(fhot($1))和行lw 4 lc rgb rgb(最大颜色)t'Hot'\
“”使用1:(fcold($1))和行lw 4 lc rgb rgb(-max_color)t'Cold'
set style fill solid 1.0
plot \
 datafile u 1:2:3 lt palette w boxes,\
 datafile u 1:2:3 lt palette lw 2 w l
max_color=1
max_diff=0.5
N_col=6
TRSP="E0"
HOTCOL="FF0000"
COLDCOL="0000FF"
RGBA_HOT="#".TRSP.HOTCOL
RGBA_COLD="#".TRSP.COLDCOL
RGB_HOT="#".HOTCOL
RGB_COLD="#".COLDCOL
#red(val) = (val < 0 ? abs(1+val/max_color) : 1)
#green(val) = (1 - abs(val)/max_color)
#blue(val) = red(-val)
#rgb(val) = 65536*int(255*red(val)) + 256*int(255*green(val)) + int(255*blue(val))
fhot(x) = 0.1*exp(-((x-400)/200)**2) + 0.8*exp(-((x-2000)/300)**2)
fcold(x) = 0.25*exp(-((x-700)/100)**6)+ 0.4 - (2e-4*(x-2500))**2
plot [400:2600] for [thr=0:N_col] '+' using (((fhot($1)-fcold($1))/max_diff*N_col>thr)?$1:1/0):(fhot($1)):(fcold($1)) with filledcurves lc rgb RGBA_HOT title '',\
     for [thr=0:N_col] '+' using ((-(fhot($1)-fcold($1))/max_diff*N_col>thr)?$1:1/0):(fhot($1)):(fcold($1)) with filledcurves lc rgb RGBA_COLD title '',\
     '' using 1:(fhot($1)) with lines lw 4 lc rgb RGB_HOT t 'Hot',\
     '' using 1:(fcold($1)) with lines lw 4 lc rgb RGB_COLD t 'Cold'
max_color=1
# for a datafile one could extract the maximum diffference with e.g.
# stats 'hotcold.dat' using 1:($3-$2)
# max_color = (abs(STATS_min_y) > abs(STATS_max_y)) ? abs(STATS_min_y) : abs(STATS_max_y)

red(val) = (val < 0 ? abs(1+val/max_color) : 1)
green(val) = (1 - abs(val)/max_color)
blue(val) = red(-val)
rgb(val) = 65536*int(255*red(val)) + 256*int(255*green(val)) + int(255*blue(val))

set yrange[0:1]
set xrange[400:2500]
set samples 200

fhot(x) = 0.1*exp(-((x-400)/200)**2) + 0.8*exp(-((x-2000)/300)**2)
fcold(x) = 0.25*exp(-((x-700)/100)**6)+ 0.4 - (2e-4*(x-2500))**2

plot \
     '+' using 1:(fhot($1)):(0):(fcold($1)-fhot($1)):(rgb(fhot($1)-fcold($1))) with vectors nohead lw 3 lc rgb var t '',\
     '' using 1:(fhot($1)) with lines lw 4 lc rgb rgb(max_color) t 'Hot',\
     '' using 1:(fcold($1)) with lines lw 4 lc rgb rgb(-max_color) t 'Cold'
     
set table $first
plot "test.dat" using 1:2:($3-$2) with table
set table $second
plot "test.dat" using 1:3:($3-$2) with table
unset table

set print $data
do for [i=1:|$first|] {
  print $first[i]
  print $second[i]
  print ""
}
set print

set yrange [-2:2]
set palette define (-1 "skyblue", 0 "gray90", 1 "pink")

splot $data using 1:2:3 with pm3d