gnuplot:带有行和列名称的矩阵(热图)的x和y轴标签 [英] gnuplot: label x and y-axis of matrix (heatmap) with row and column names

查看:147
本文介绍了gnuplot:带有行和列名称的矩阵(热图)的x和y轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绝对是gnuplot的新手,在谷歌搜索后没有找到有效的解决方案.

I'm absolutely new to gnuplot and did not find a working solution after googling.

我有一个看起来像这样的数据矩阵:

I have a data matrix looking something like this:

  A B C D E
A 0 2 3 4 5
B 6 0 8 9 0
C 1 2 0 4 5
D 6 7 8 0 0
E 1 2 3 4 0

我想做的是用plot 'result.csv' matrix with image绘制热图,x轴标记为A-E,y轴标记为A-E.该矩阵的大小并不总是相同,但行数始终等于cols数,并且始终带有标签.

What I would like to do is plotting a heatmap with plot 'result.csv' matrix with image, with the x-axis labeled with A-E and the y-axis labeled with A-E. This matrix does not always have the same size, but the number of row always equals the number of cols and it's always labeled.

有人可以帮我这个忙吗?我想我必须使用using命令,但是到目前为止,这对我来说就像是完全的伏都教...

Could someone help me out with this? I guess I have to use the using command, but up to now this appears like complete voodoo to me...

非常感谢!

推荐答案

这实际上是一个斗鸡,没有一些* nix shell魔术我就无法实现.

This one is actually a doosie and I can't make it happen without some *nix shell magic.

首先,我们要获取x tic标签和y tic标签:

First, we want to get the x tic labels and y tic labels:

XTICS="`awk 'BEGIN{getline}{printf "%s ",$1}' test.dat`"
YTICS="`head -1 test.dat`"

这时,XTICS是字符串"F G H I J",YTICS是字符串"A B C D E".

At this point, XTICS is the string "F G H I J" and YTICS is the string "A B C D E".

现在,我们要通过迭代设置xtics:

Now, we want to set the xtics by iteration:

set for [i=1:words(XTICS)] xtics ( word(XTICS,i) i-1 )
set for [i=1:words(YTICS)] ytics ( word(YTICS,i) i-1 )

我们使用了2个gnuplot内置函数(wordwords). words(string)计算给定字符串中有多少个单词(单词是用空格分隔的字符序列). word(string,n)返回字符串中的第n个单词.

We've used 2 gnuplot builtin functions (word and words). words(string) counts how many words there are in the given string (a word is a character sequence separated by spaces). word(string,n) returns the n'th word in the string.

现在,我们可以绘制您的数据文件了……唯一的问题是matrix想要使用数据文件中的所有行和列.您也许可以使用every关键字来减少实际读取的行/列,但我不知道如何在矩阵文件上执行此操作-我认为仅依靠Shell实用程序可能会更容易(awksed)

Now, we can plot your datafile ... The only problem is that matrix wants to use all rows and columns in your datafile. You might be able to cut down the rows/columns actually read by using the every keyword, but I don't know how to do that on matrix files -- and I think it's probably easier to just keep on relying on shell utilities (awk and sed)

plot "<awk '{$1=\"\"}1' test.dat | sed '1 d'" matrix w image
#######^ replace the first field with nothing
################################## ^ delete first line

现在,您的情节(希望如此)看起来像您想要的样子.

And now your plot (hopefully) looks the way you want it to.

还请注意,由于我们使用了迭代,因此该脚本只能在gnuplot 4.3或更高版本中使用-由于当前稳定版本为4.6,希望可以.

这篇关于gnuplot:带有行和列名称的矩阵(热图)的x和y轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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