gnuplot: 二维矩阵数据的图表绘制

11

如何在Gnuplot中绘制(2D绘图)一个具有以下数据结构的矩阵,使用第一行和第一列作为x和y刻度(第一行的第一个数字是列数),并通过颜色映射来表示其余值,以便在2D平面上可见?

4 0.5 0.6 0.7 0.8
1 -6.20 -6.35 -6.59 -6.02
2 -6.39 -6.52 -6.31 -6.00
3 -6.36 -6.48 -6.15 -5.90
4 -5.79 -5.91 -5.87 -5.46
1个回答

15

您可以使用 matrix nonuniform 格式绘制这些数据。

要获取热力图,您可以使用 with image(正则网格,无插值,每个数据点一个四边形),或者使用 with pm3d 的 splot(还支持不规则网格和插值,将为四个相邻的数据点绘制一个四边形)。

  1. with image

    set autoscale xfix
    set autoscale yfix
    set autoscale cbfix
    plot 'data.dat' matrix nonuniform with image notitle
    

这里插入图像描述

  1. pm3d

set autoscale xfix
set autoscale yfix
set autoscale cbfix
set pm3d map
splot 'data.dat' matrix nonuniform notitle

这里输入图片描述


谢谢,它起作用了。我尝试使用矩阵和'splot'命令来处理'data.txt'文件,但它只给出列数和行数作为索引。 - Jack
不,“with matrix”仅仅是错误的语法,“with”需要一个绘图样式。对于您的数据格式,技巧是“matrix nonuniform”。 - Christoph
我们如何将数据包含在热力图中 - 将每个数据值插入到其对应的 (x,y) 网格位置上? - Gathide
1
@Gathide 使用 labels 绘图样式,参见例如 https://dev59.com/MoXca4cB1Zd3GeqPHV4E#27049991 - Christoph
1
在这样的图中,总是会有不同颜色的正方形。我能否用不同颜色的点(圆点)获得相同的图? - Bapi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接