使用gnuplot中的图像矩阵使用文件中的多个调色板和空标签 [英] Multiple palettes and empty labels from file entries using matrix with image in gnuplot

查看:76
本文介绍了使用gnuplot中的图像矩阵使用文件中的多个调色板和空标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a file with a 4x4 score matrix and I'd like to plot the upper triangular with one color palette and the lower triangular with a different one, overlaying the score value (MWE at the bottom).

原始文件如下

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个不同的调色板.

First, I created two separate files and used multiplot to have 2 different palettes.

FILE1(上三角)

FILE1 (upper triangular)

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(下三角)

FILE2 (lower triangular)

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

第二,我用来绘制得分值

Second, I plot the score values with

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

但是,"nan"并没有被解释为空白/空,而是被跳过了,而是写到了情节上.

However, the 'nan' isn't interpreted as blank/empty and skipped but written onto the plot.

有什么想法如何跳过nans并让gnuplot从数据文件的各个条目中绘制空标签吗?

Any idea how to skip the nans and make gnuplot plot empty labels from individual entries of the data files?

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

The ternary operator in the following fashion do not seem to do the job

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

推荐答案

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

You don't need to use multiplot and two separate files (I also couldn't get this working with the labels).

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

Just define a single palette, which contains as negative values one palette and as positive values the other palette. Based on the x and y-value from the single file you show first, you can now distinguish if the color value should be taken from the negative or from the positive palette part:

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'

这篇关于使用gnuplot中的图像矩阵使用文件中的多个调色板和空标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆