【问题标题】:pm3d in gnuplot with binary data带有二进制数据的gnuplot中的pm3d
【发布时间】:2013-04-08 11:44:34
【问题描述】:

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

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-command 不起作用,因为我在二进制文件中没有空行。我收到错误消息:

>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.

根据http://gnuplot.sourceforge.net/demo/image2.html中的演示脚本,我必须指定记录长度(我还是不明白)。但是,使用演示页面中的此脚本和带有 pm3d 的命令会获得相同的错误消息:

splot 'scatter2.bin' binary record=30:30:29:26 u 1:2:3  w pm3d

那么如何正确地从二进制文件中绘制这四维数据呢?

编辑:谢谢,mgilson。现在它工作正常。仅作记录:我的 fortran 代码-sn-p:

 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'

【问题讨论】:

    标签: binary fortran gnuplot binary-data


    【解决方案1】:

    很好的问题,感谢您发布它。这是我之前没有花太多时间使用的 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 个浮点数,所以它成为 record 列表中的第一个索引。 -1 表示 gnuplot 应该一直读取记录,直到找到文件末尾。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多