非均匀网格上具有Gnuplot的热图 [英] Heatmap with Gnuplot on a non-uniform grid

查看:70
本文介绍了非均匀网格上具有Gnuplot的热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用基于非均匀网格的gnuplot创建一个热图,这意味着我的x轴箱没有相同的宽度,我不知道该怎么做,因为当我绘制我的带有带有图像"的数据,我得到大小一致的框,这些框完全不对应于我的坐标(因为图像"将数据视为矩阵,我猜是这样).因此,我想找到一种方法来获取不均匀的盒子,这些盒子也位于笛卡尔平面上的正确位置.

我的数据看起来像这样:

1 1 0.2
1 2 0.8
1 3 0.1
1 4 0.2

2 1 0.7
2 2 0.2
2 3 0.3
2 4 0.1

5 1 0.2
5 2 0.4
5 3 0.1
5 4 0.9

7 1 0.3
7 2 0.2
7 3 0.9
7 4 0.6

如果我在Gnuplot上运行此命令

set xrange [1:10]
p 'mydata.dat' with image

我得到一个带有16个宽度和高度相同的盒子的图像(显然我在Stackoverflow上没有足够的声誉"来发布图像,否则我会这样做),但是理想情况下,我希望这些盒子具有不同的宽度宽度,并在平面上的正确位置.例如,第一个方框的范围应该是1到2,第二个方框的范围应该是2到5,第三个方框的范围应该是5到7,最后一个方框的范围应该是7到10(这就是我写set xrange [1:10]的原因).

有人可以帮我吗?非常感谢你!

解决方案

最简单(也许唯一可行)的方法是添加一些虚拟数据点并使用splot ... with pm3d.这种绘图样式可处理带有一般四边形的热图.

image绘图样式为每个数据点绘制一个框(一个大像素),而pm3d将每个数据点作为一个或多个四边形的角.每个四边形的颜色由边角的值确定,并且可以通过set pm3d corners2color进行调整.

因此,在您的情况下,您需要将4x4矩阵扩展为5x5矩阵(向右和顶部扩展),但是选择左下角以确定颜色set pm3d corners2color c1.

更改后的数据文件为:

1 1 0.2
1 2 0.8
1 3 0.1
1 4 0.2
1 5 0.5

2 1 0.7
2 2 0.2
2 3 0.3
2 4 0.1
2 5 0.5

5 1 0.2
5 2 0.4
5 3 0.1
5 4 0.9
5 5 0.5

7 1 0.3
7 2 0.2
7 3 0.9
7 4 0.6
7 5 0.5

10 1 0.5
10 2 0.5
10 3 0.5
10 4 0.5
10 5 0.5

要绘制它,请使用

set pm3d map corners2color c1
set autoscale fix
set ytics 1
splot 'mydata.dat' using 1:($2-0.5):3 notitle

4.6.3的结果是:

通常,虚拟数据点的z值无关紧要,但是在上面的脚本中,它应该位于最小值和最大值之间,以允许set autoscale fix在色标上正常工作. /p>

如果您不想手动更改数据文件,则可以使用一些脚本来完成,但这是另一个问题.

I would like to create a heatmap with gnuplot based on a non-uniform grid, meaning that my x axis bins do not have all the same width, and I can't figure out how to do that because when I plot my data with for example "with image" I get uniformly sized boxes which do no correspond to my coordinates at all (because "image" treats the data just as matrix I guess). So I would like to find a method to get non-uniform boxes which are also positioned in the right place on the Cartesian plane.

My data look something like this:

1 1 0.2
1 2 0.8
1 3 0.1
1 4 0.2

2 1 0.7
2 2 0.2
2 3 0.3
2 4 0.1

5 1 0.2
5 2 0.4
5 3 0.1
5 4 0.9

7 1 0.3
7 2 0.2
7 3 0.9
7 4 0.6

If I run this command on Gnuplot

set xrange [1:10]
p 'mydata.dat' with image

I get an image with 16 boxes that have the same width and height (apparently I don't have enough "reputation" on Stackoverflow to post an image, otherwise I would), but ideally I would like the boxes to have different widths and be in the right place on the plane. For example the first box should range from 1 to 2, the second one from 2 to 5, the third one from 5 to 7, and the last one from 7 to 10 (which is why I wrote set xrange [1:10]).

Could anyone help me please? Thank you very much!

解决方案

The easiest (maybe only viable) way is to add some dummy data points and use splot ... with pm3d. This plotting style handles heatmaps with general quadrangles.

The image plotting style plots one box (one big pixel) for each data point, while pm3d takes each data point as corner of one or more quadrangles. The color of each quadrangles is determined by the values of the corners and is adjustable with set pm3d corners2color.

So, in your case you need to expand the 4x4 matrix to a 5x5 matrix (expand to right and top), but select the lower left corner to determine the color set pm3d corners2color c1.

The changed data file is then:

1 1 0.2
1 2 0.8
1 3 0.1
1 4 0.2
1 5 0.5

2 1 0.7
2 2 0.2
2 3 0.3
2 4 0.1
2 5 0.5

5 1 0.2
5 2 0.4
5 3 0.1
5 4 0.9
5 5 0.5

7 1 0.3
7 2 0.2
7 3 0.9
7 4 0.6
7 5 0.5

10 1 0.5
10 2 0.5
10 3 0.5
10 4 0.5
10 5 0.5

To plot it use

set pm3d map corners2color c1
set autoscale fix
set ytics 1
splot 'mydata.dat' using 1:($2-0.5):3 notitle

The result with 4.6.3 is:

In general, the z-value of the dummy data points doesn't matter, but in the above script it should lay somewhere between minimum and maximum values to allow set autoscale fix to work properly on the color scale.

If you don't want to change the data file manually, you could do it with some script, but that's a different question.

这篇关于非均匀网格上具有Gnuplot的热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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