matrix - 在 gnuplot 中使用带有图像的矩阵的文件条目中的多个调色板和空标签

标签 matrix gnuplot label 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 来获得 2 个不同的调色板。

FILE1(上三角)

0.00 0.65 0.65 0.25
nan  0.00 0.75 0.25
nan nan 0.00 0.25
nan nan nan 0.00

FILE2(下三角)

0.00 nan nan nan
0.25 0.00 nan nan
0.50 0.60 0.00 nan
0.75 0.25 0.10 0.00

其次,我绘制得分值

using 1:2:( sprintf('%.2f', $3 ) )

但是,“nan”不会被解释为空白/空,也不会被跳过,而是会写入绘图中。

知道如何跳过 nans 并使 gnuplot 从数据文件的各个条目中绘制空标签吗?

以下方式的三元运算符似乎无法完成这项工作

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

最佳答案

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

只需定义一个调色板,其中包含负值的一个调色板和正值的另一个调色板。根据您首先显示的单个文件中的 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'

enter image description here

关于matrix - 在 gnuplot 中使用带有图像的矩阵的文件条目中的多个调色板和空标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27045964/

相关文章:

c++ - 找不到用 C++ 编写的 gnuplot.exe 路径

Java动态矩阵结构

matlab - 使用 accumarray 输出矩阵

arrays - 如何计算矩阵中值(正常运行时间)连续出现的长度?

d3.js - NVD3 : How to get values from tooltip or legend instead of labels?

html - Rails simple_form label_html

Javascript/D3 --- 标签的条件格式

c++ - 如何找到近奇异矩阵的逆矩阵?

java - 如何从 Java 环境运行 Gnuplot 脚本?

plot - Gnuplot:网格后面多图中的第二个图例