【问题标题】:Create 2D histogram (heat map) in gnuplot from raw (unbinned) data从原始(未合并)数据在 gnuplot 中创建 2D 直方图(热图)
【发布时间】:2017-07-19 17:44:01
【问题描述】:

我有一个包含 2 列原始未合并数据(x 和 y 位移)的文件。文件中的每一行对应一个新的时间步。我想将 x 和 y 位移相互关联。

对于每一行,我想将 x 值和 y 值分箱到直方图中,然后将一个“计数”添加到相应的 (x,y) 箱中。

我有一个代码已经完成了大部分工作,它将每个轴分箱,然后在相应的空间中放置一个点/“计数”,但问题是它没有将“计数”加在一起。相反,这些点只是相互重叠。您可以看到一些点看起来比其他点看起来更粗/更暗,其中多个点相互重叠。像这样:

Gnuplot output with my full data set. Shows the bolder overlapping points

我的问题是:我如何才能将彼此重叠的点/“计数”(如我的图像中)加在一起,以便我可以看到相关性较高的区域在哪里彩色地图或类似的东西?

I'd like my plot to look like this instead, with the color value corresponding to the number of points/'counts' in the 2D bin

我的 gnuplot 代码做了我想做的事:

#!/usr/local/bin/gnuplot

set term postscript eps enhanced color
set encoding utf8
set offsets
set style fill solid

bin(x,width,min)=width*(floor((abs(x) - min)/width) + 0.5)  + min

set output '2d.test.eps'
set palette defined (-1 "red", 0 "white", 1 "blue")
set cbrange [0:10]

binwidth=0.1
binwidth=0.1
xmin=-360
ymin=-360
set boxwidth binwidth*0.75

set view map
splot '2d.dat' using (bin($1,binwidth,xmin)):(bin($2,binwidth,ymin)):(1.0) not

数据文件格式:

   0.864    3.868
   1.878    3.617
   0.138    2.787
   0.646    3.220
  -0.969    3.176
  -0.447    3.031
  -0.316    3.130
   0.205    3.342
  -1.127    3.661
  -1.349    3.702
...

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    如果您愿意使用 awk 进行计算并使用 uniq 进行计数,您可以使用:

    awk 'function abs(x){return (sqrt(x*x))}{print 0.1*(int((abs($1)+360)/0.1)+0.5)-360" "0.1*(int((abs($2)+360)/0.1)+0.5)-360}' input.dat | sort | uniq -c > output.dat
    

    由于 uniq 预先添加了您需要绘制的计数

    set view map
    splot "output.dat" 2:3:1 matrix with image
    

    这也应该可以直接在 gnuplot 中实现:

    splot "<awk 'function abs(x){return (sqrt(x*x))}{print 0.1*(int((abs($1)+360)/0.1)+0.5)-360\" \"0.1*(int((abs($2)+360)/0.1)+0.5)-360}' data.dat | sort | uniq -c" u 2:3:1  2:3:1 matrix with image
    

    (注意转义的“字符!)

    【讨论】:

      猜你喜欢
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-08
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      相关资源
      最近更新 更多