Binary 带有二进制数据的gnuplot中的pm3d

Binary 带有二进制数据的gnuplot中的pm3d,binary,fortran,gnuplot,binary-data,Binary,Fortran,Gnuplot,Binary Data,我有一些包含内容的数据文件 a1 b1 c1 d1 a1 b2 c2 d2 ... [blank line] a2 b1 c1 d1 a2 b2 c2 d2 ... 我用gnuplot用 splot 'file' u 1:2:3:4 w pm3d. 现在,我想使用一个二进制文件。我使用Fortran创建了这个文件,使用的是无格式流访问(直接或顺序访问不能直接工作)。通过将gnuplot与 splot 'file' binary format='%float%float%float%float

我有一些包含内容的数据文件

a1 b1 c1 d1
a1 b2 c2 d2
...
[blank line]
a2 b1 c1 d1
a2 b2 c2 d2
...
我用gnuplot用

splot 'file' u 1:2:3:4 w pm3d.
现在,我想使用一个二进制文件。我使用Fortran创建了这个文件,使用的是无格式流访问(直接或顺序访问不能直接工作)。通过将gnuplot与

splot 'file' binary format='%float%float%float%float' u 1:2:3
我得到了一个普通的3D图。但是,PM3D命令不起作用,因为二进制文件中没有空行。我收到错误消息:

>splot 'file' binary format='%float%float%float%float' u 1:2:3:4 w pm3d
Warning: Single isoline (scan) is not enough for a pm3d plot.
Hint: Missing blank lines in the data file? See 'help pm3d' and FAQ.
splot 'scatter2.bin' binary record=30:30:29:26 u 1:2:3  w pm3d
根据中的演示脚本,我必须指定记录长度(我仍然不太理解)。但是,使用演示页面中的此脚本和pm3d命令会获得相同的错误消息:

>splot 'file' binary format='%float%float%float%float' u 1:2:3:4 w pm3d
Warning: Single isoline (scan) is not enough for a pm3d plot.
Hint: Missing blank lines in the data file? See 'help pm3d' and FAQ.
splot 'scatter2.bin' binary record=30:30:29:26 u 1:2:3  w pm3d
那么,如何从二进制文件中正确地绘制这个四维数据呢

编辑:谢谢,米吉尔森。现在它工作得很好。仅供记录:我的fortran代码片段:

 open(unit=83,file=fname,action='write',status='replace',access='stream',form='unformatted')
 a= 0.d0
 b= 0.d0
 do i=1,200
    do j=1,100  
       write(83)real(a),real(b),c(i,j),d(i,j)
       b = b + db
    end do
    a = a + da
    b = 0.d0
 end do
close(83)
gnuplot命令:

 set pm3d map
 set contour
 set cntrparam levels 20
 set cntrparam bspline
 unset clabel
splot 'fname' binary record=(100,-1) format='%float' u 1:2:3:4 t 'd as pm3d-projection, c as contour'

很好的问题,谢谢你发帖。这是gnuplot的一个角落,我以前没有花太多时间。首先,我需要生成一点测试数据——我使用了python,但您可以同样轻松地使用
fortran

请注意,我的输入数组(
b
)只是一个10x10数组。数据文件中的前两个“列”只是索引(i,j),但您可以使用任何东西

>>> import numpy as np
>>> a = np.arange(10)
>>> b = a[None,:]+a[:,None]
>>> b
array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9],
       [ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10],
       [ 2,  3,  4,  5,  6,  7,  8,  9, 10, 11],
       [ 3,  4,  5,  6,  7,  8,  9, 10, 11, 12],
       [ 4,  5,  6,  7,  8,  9, 10, 11, 12, 13],
       [ 5,  6,  7,  8,  9, 10, 11, 12, 13, 14],
       [ 6,  7,  8,  9, 10, 11, 12, 13, 14, 15],
       [ 7,  8,  9, 10, 11, 12, 13, 14, 15, 16],
       [ 8,  9, 10, 11, 12, 13, 14, 15, 16, 17],
       [ 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]])
>>> with open('foo.dat','wb') as foo:
...     for (i,j),dat in np.ndenumerate(b):
...         s = struct.pack('4f',i,j,dat,dat)
...         foo.write(s)
... 
所以这里我只为每个数据点向文件中写入4个浮点值。同样,这是您使用
fortran
所做的工作。现在绘制它:

splot 'foo.dat' binary record=(10,-1) format='%float' u 1:2:3:4 w pm3d
我相信这规定了每个“扫描”都是一个“记录”。因为我知道每个扫描将有10个浮点数长,所以这将成为
记录
列表中的第一个索引。
-1
表示gnuplot应该一直读取记录,直到找到文件的结尾