【问题标题】:Gnuplot pm3d: 'NaN value' removes all surrounding rectanglesGnuplot pm3d:“NaN 值”删除所有周围的矩形
【发布时间】:2020-05-15 17:18:48
【问题描述】:

我想绘制一个 pm3d 地图,其中数据点在轴上不等距。 由于 x 轴和 y 轴的间距相同,因此它是对称的。

问题是每当一个值为“NaN”时,所有四个周围的矩形 没有绘制。例如,在下面的数据文件中,这种情况发生在 (x,y)=(0.14,0.33)

如果值不是“NaN”,则重新出现四个矩形。 我发现了这个问题,当我试图只绘制 >0 或

我尝试搜索文档和互联网,但找不到任何相关内容。 有什么解决办法吗?

剧情简介:

set view map
set pm3d at b
set style data pm3d
set pm3d corners2color c1
set size ratio 1
set autoscale fix
set cbrange [-25:25]
set palette defined (-25 "blue", 0 "white", 25 "red")
set term png
set output "test.png"
splot "data.txt" u 1:2:3 notitle
set output

数据文件:

0.0 0.0 1
0.0 0.08 -2
0.0 0.14 3
0.0 0.33 -4
0.0 0.46 5
0.0 0.55 5

0.08 0.0 -6
0.08 0.08 7
0.08 0.14 -8
0.08 0.33 9
0.08 0.46 -10
0.08 0.55 -10

0.14 0.0 11
0.14 0.08 -12
0.14 0.14 13
0.14 0.33 NaN
0.14 0.46 15
0.14 0.55 15

0.33 0.0 -16
0.33 0.08 17
0.33 0.14 -18
0.33 0.33 19
0.33 0.46 -20
0.33 0.55 -20

0.46 0.0 21
0.46 0.08 -22
0.46 0.14 23
0.46 0.33 -24
0.46 0.46 25
0.46 0.55 25

0.55 0.0 21
0.55 0.08 -22
0.55 0.14 23
0.55 0.33 -24
0.55 0.46 25
0.55 0.55 25

【问题讨论】:

  • 你检查过这个吗? stackoverflow.com/a/56039394/7295599
  • pm3d 模式正在为表面分配颜色,但由于 NAN 坐标,表面上有一个洞。在您以某种方式修复孔之前,也许通过从周围的点进行插值,将不会有一个完整的表面可供它着色。
  • 感谢你们两位的 cmets。您的链接对我帮助很大,请参阅下面的答案。不过,@theozh,我对脚本中的“使用”部分有疑问。即使有 gnuplot 文档,也不清楚那里发生了什么。显然需要一个需要两个变量/维度的函数,尽管它从来不需要(我指的是 ndx、pdx 等)。你能详细说明一下使用线吗?

标签: gnuplot heatmap


【解决方案1】:

感谢@theozh 的评论,我找到了解决此问题的方法。 我将@theozh 在Plotting Heatmap with different column/line widths 下的脚本采用到下面的表格中。这会产生文件

1 -6 11 -16 21
-2 7 -12 17 -22
3 -8 13 -18 23
-4 9 NaN 19 -24
5 -10 15 -20 25

这个plot. 这是最好的解决方案,因为无论如何数据都具有这种格式,并且坐标是我读入的不同文件。 剧情:

CoordsX = "0.04 0.11 0.24 0.40 0.51"
CoordsY = "0.04 0.11 0.24 0.40 0.51"
dimX = words(CoordsX)
dimY = words(CoordsY)
dx(i) = (word(CoordsX,i)-word(CoordsX,i-1))*0.5
dy(i) = (word(CoordsY,i)-word(CoordsY,i-1))*0.5
ndx(i,j) = word(CoordsX,i) - (i-1<1        ? dx(i+1) : dx(i))
pdx(i,j) = word(CoordsX,i) + (i+1>ColCount ? dx(i)   : dx(i+1))
ndy(i,j) = word(CoordsY,j) - (j-1<1        ? dy(j+1) : dy(j))
pdy(i,j) = word(CoordsY,j) + (j+1>RowCount ? dy(j)   : dy(j+1))

set xrange[ndx(1,1):pdx(ColCount,1)]
set yrange[ndy(1,1):pdy(1,RowCount)]
set tic out
max = 25
set cbrange [-max:max]
set palette defined (-max "blue", 0 "white", max "red")

set term png
set output "test.png"
plot for [i=1:dim_x] file u (real(word(CoordsX,i))):1:(ndx(i,int($0))):(pdx(i,int($0))):(ndy(i,int($0+1))):(pdy(i,int($0+1))):i with boxxyerror fs solid 1.0 palette notitle
set output
### end of code

【讨论】:

    猜你喜欢
    • 2011-05-07
    • 1970-01-01
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-30
    • 1970-01-01
    • 2017-05-11
    相关资源
    最近更新 更多