【问题标题】:gnuplot: 3D plot of a matrix of datagnuplot:数据矩阵的 3D 图
【发布时间】:2012-10-05 16:04:21
【问题描述】:

如何在 Gnuplot 中绘制(3D 图)具有这种数据结构的矩阵, 使用第一行和第一列作为 x 和 y 刻度(第一行的第一个数字是列数)?

4 0.5 0.6 0.7 0.8
1 -6.20 -6.35 -6.59 -6.02
2 -6.39 -6.52 -6.31 -6.00
3 -6.36 -6.48 -6.15 -5.90
4 -5.79 -5.91 -5.87 -5.46

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    正是这种数据格式可以用matrix nonuniform读入:

    set view 50,20
    set ticslevel 0
    splot 'data.txt' matrix nonuniform with lines t ''
    

    这会生成正确的抽动,就像在数据文件中指定的那样:

    【讨论】:

      【解决方案2】:

      要绘制 4D 图,使用颜色作为第 4 维,您可以使用

      splot  '1.txt' using 2:3:4:5  every ::1  palette
      #  |                              |
      #  |                              |
      # used for 3d plots            skip the header line
      

      或者你想画一张不同的图,x 和 y 是第一列和第一行,矩阵中的数字只是代表 z?然后使用以下内容:

      splot '1.txt' every ::1:1 matrix
      

      要添加一些效果,您可以将其更改为

      set dgrid3d 4,4
      splot '1.txt' every ::1:1 matrix with lines
      

      【讨论】:

      • 非常感谢!最后一个解决方案“set dgrid3d 4,4; splot '1.txt' every ::1:1 matrix with lines”对我有好处。只有我想在图表底部使用 x 刻度“0.5 0.6 0.7 0.8”和 y 刻度“1 2 3 4”。有可能吗?
      • @micheletuttafesta:你可以使用set xtics (0.5, 0.6, 0.7, 0.8)。 AFAIK,gnuplot 没有从输入文件中获取数字的方法,因此您必须生成 gnuplot 脚本:head -n1 input.txt | sed 's/ /,/g;s/^/set xtics(/;s/$/)/' > script.gp
      • 感谢 choroba!你的建议是我的最终解决方案
      • 实际上,gnuplot 有一个命令可以准确读取这种数据格式,并且它也使用正确的抽动,请参阅我的答案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-09
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      • 2022-06-30
      • 1970-01-01
      相关资源
      最近更新 更多