Matrix 在gnuplot中使用带有图像的矩阵从文件条目中选择多个选项板和空标签

Matrix 在gnuplot中使用带有图像的矩阵从文件条目中选择多个选项板和空标签,matrix,gnuplot,labels,color-palette,Matrix,Gnuplot,Labels,Color Palette,我有一个带有4x4分数矩阵的文件,我想用一个调色板绘制上三角,用另一个调色板绘制下三角,覆盖分数值(底部的MWE) 原始文件如下所示 0.00 0.65 0.65 0.25 0.25 0.00 0.75 0.25 0.50 0.60 0.00 0.25 0.75 0.25 0.10 0.00 首先,我创建了两个单独的文件,并使用multiplot创建了两个不同的选项板 文件1(上三角) 文件2(下三角) 第二,我用 using 1:2:( sprintf('%.2f', $3 ) ) 但是,

我有一个带有4x4分数矩阵的文件,我想用一个调色板绘制上三角,用另一个调色板绘制下三角,覆盖分数值(底部的MWE)

原始文件如下所示

0.00 0.65 0.65 0.25
0.25 0.00 0.75 0.25
0.50 0.60 0.00 0.25
0.75 0.25 0.10 0.00
首先,我创建了两个单独的文件,并使用multiplot创建了两个不同的选项板

文件1(上三角)

文件2(下三角)

第二,我用

using 1:2:( sprintf('%.2f', $3 ) )
但是,“nan”不会被解释为空白/空并被跳过,而是写入到绘图中

您知道如何跳过NAN并使gnuplot从数据文件的各个条目中打印空标签吗

以下方式的三元运算符似乎不起作用

using 1:2:( $3 == 'nan' ? 1/0 : sprintf('%.2f', $3 ))
谢谢



您不需要使用multiplot和两个单独的文件(我也无法使用标签)

只需定义一个调色板,其中一个调色板包含负值,另一个调色板包含正值。根据首先显示的单个文件的x和y值,现在可以区分颜色值是从负片还是从正片调色板部分获取:

set autoscale fix
set cbrange [-1:1]
unset colorbox
unset key

set palette defined (-1.0 "#31a354", -0.1 "#a1d99b", 0 "white", 0.1 "#9ecae1", 1.0 "#3182bd")

plot 'FILE' matrix using 1:2:($1<$2 ? -$3 : $3) with image,\
     '' matrix using 1:2:(sprintf('%.2f', $3)) with labels font ',16'
设置自动缩放修复
设置cbrange[-1:1]
未设置色盒
取消设置键
设定调色板定义(-1.0“#31a354”、-0.1“#a1d99b”、0“白色”、0.1“#9ecae1”、1.0“#3182bd”)

使用1:2:($1Thanks!事实上,您的解决方案一次解决了两个问题,因为它避免了将原始文件拆分为两个单独的文件,因此不再需要处理NAN。如果您仍然喜欢使用NAN,那么一个解决方案是使用1:2:($3!=$3)?“”:sprintf('.2f',$3)使用如下测试
,表示NaN的属性不等于其自身,因此
A=NaN;如果(A!=A)打印“A不是数字”
(信用证E.A.Merrit)
using 1:2:( $3 == 'nan' ? 1/0 : sprintf('%.2f', $3 ))
set multiplot
set autoscale fix
unset key

set datafile missing "nan"
set cbrange [0:1]
unset colorbox

set palette defined (0 "white", 0.1 "#9ecae1", 1.0 "#3182bd")

plot FILE1 matrix with image, \
    FILE1 matrix using 1:2:( sprintf('%.2f', $3) ) with labels font ',16'

set palette defined (0 "white", 0.1 "#a1d99b", 1.0 "#31a354")

plot FILE2 matrix with image, \
    FILE2 matrix using 1:2:( sprintf('%.2f', $3) ) with labels font ',16'

unset multiplot
set autoscale fix
set cbrange [-1:1]
unset colorbox
unset key

set palette defined (-1.0 "#31a354", -0.1 "#a1d99b", 0 "white", 0.1 "#9ecae1", 1.0 "#3182bd")

plot 'FILE' matrix using 1:2:($1<$2 ? -$3 : $3) with image,\
     '' matrix using 1:2:(sprintf('%.2f', $3)) with labels font ',16'