【问题标题】:Gnuplot - Unable to properly plot two matrices with different sizesGnuplot - 无法正确绘制两个不同大小的矩阵
【发布时间】:2021-04-27 21:51:21
【问题描述】:

我的数据文件如下:

#smaller matrix
5   0.00    0.25    0.50    0.75    1.00
0.00    1   2   3   4   5
0.25    5   4   3   2   1
0.50    1   2   3   4   5
0.75    5   4   3   2   1
1.00    1   2   3   4   5


#bigger matrix
8   0.00    0.25    0.50    0.75    1.00    1.25    1.50    1.75
0.00     1  2   3   4   5   6   7   8
0.25    5   4   3   2   1   0   1   2
0.50    1   2   3   4   5   6   7   8
0.75    5   4   3   2   1   0   1   2
1.00    1   2   3   4   5   6   7   8
1.25    5   4   3   2   1   0   1   2
1.50    1   2   3   4   5   6   7   8
1.75    5   4   3   2   1   0   1   2

gnuplot脚本如下:

set term png size 900, 400
set output 'matrices-test.png'
set multiplot layout 1,2

set xrange [0:1.0]
set yrange [0:1.0]
plot 'matrices-test' index 0 nonuniform matrix w image

set xrange [0:1.75]
set yrange [0:1.75]
plot 'matrices-test' index 1 nonuniform matrix w image

unset multiplot

当我运行这个脚本时,较小的矩阵会变形。图像倾斜,数据似乎被破坏:

如果我将每个矩阵放入一个单独的文件中,它们都可以毫无问题地绘制出来。

我做错了吗?或者这是gnuplot中的一个错误? (我在 Ubuntu Linux 中使用的是最新版本 5.4.1。)

【问题讨论】:

    标签: matrix gnuplot


    【解决方案1】:

    您遇到了程序错误。 您的脚本在开发版本 (gnuplot 5.5) 中可以正常工作,并且该修复将包含在下一个 5.4 稳定版本中。

    解决方法:

    该错误与输入文件中有多个数据块有关。如果矩阵在单独的文件中或者如果它们被加载到单独的数据块中并从那里绘制,则不会触发它。因此,一种解决方法是从外部选择第一个数据块:

    unset key
    set auto noextend
    
    set multiplot layout 1,2
    
    plot '<head --lines=7 matrices.dat' index 0 nonuniform matrix w image
    plot 'matrices.dat' index 1 nonuniform matrix w image
    
    unset multiplot
    

    【讨论】:

      【解决方案2】:

      由于 Ethan 的解决方案包含特定的 Linux 命令'&lt;head --lines=7 matrices.dat'),所以让我添加一个独立于平台的gnuplot-only 解决方法。但是,它仅限于 gnuplot 版本 >=5.2.7,因为在早期版本中 strcol() 仅限于大约。仅 63 个字符。好吧,只要行少于 63 个字符,它就可能适用于早期版本。

      代码:

      ### plot two matrices from same file
      # requires gnuplot >=5.2.7
      reset session
      
      $Data <<EOD
      #smaller matrix
      5   0.00    0.25    0.50    0.75    1.00
      0.00    1   2   3   4   5
      0.25    5   4   3   2   1
      0.50    1   2   3   4   5
      0.75    5   4   3   2   1
      1.00    1   2   3   4   5
      
      
      #bigger matrix
      8   0.00    0.25    0.50    0.75    1.00    1.25    1.50    1.75
      0.00    1   2   3   4   5   6   7   8
      0.25    5   4   3   2   1   0   1   2
      0.50    1   2   3   4   5   6   7   8
      0.75    5   4   3   2   1   0   1   2
      1.00    1   2   3   4   5   6   7   8
      1.25    5   4   3   2   1   0   1   2
      1.50    1   2   3   4   5   6   7   8
      1.75    5   4   3   2   1   0   1   2
      EOD
      
      set datafile separator "\n"
      set table $Matrix1
          plot $Data u (strcol(1)) index 0 w table
      unset table
      set datafile separator whitespace
      
      set size ratio 1
      unset key
      
      set multiplot layout 1,2
          set xrange [-0.25:1.25]
          set yrange [-0.25:1.25]
          plot $Matrix1 nonuniform matrix w image
          
          set xrange [-0.25:2.0]
          set yrange [-0.25:2.0]
          plot $Data index 1 nonuniform matrix w image
      unset multiplot
      ### end of code
      

      结果:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-09-23
        • 1970-01-01
        • 1970-01-01
        • 2016-10-03
        • 2021-10-26
        • 1970-01-01
        相关资源
        最近更新 更多