【问题标题】:Plotting file rows as a function of first row in sequence with gnuplot使用gnuplot按顺序将文件行绘制为第一行的函数
【发布时间】:2022-04-30 07:18:18
【问题描述】:

我正在尝试对系统(1D)波函数概率密度的时间演化进行动画处理,并且已经创建了一个文件,其中包含 x 中每个点的幅度:文件的第一行是 x坐标分区,后面几行是这些点每个时间步的幅值。

这是一个简化的例子:

0.0 0.2 0.4 0.6 0.8 1.0 #x partition
2.0 2.1 2.3 2.2 1.9 1.6 #1st time-step amplitud value of each 
1.9 2.0 2.2 2.2 2.1 1.9 #2nd time-step amplitud value of each
          .
          .
          .
4.0 4.2 3.9 3.5 3.2 2.9 #nth time-step amplitud value of each

关键是每个时间步 (i) 我必须绘制第 i 行与第一行的图,但不知道该怎么做。

最后我想用这个数据文件用 gnuplot 制作一个动画 gif。

【问题讨论】:

  • 欢迎。请不要问“你会推荐学习脚本吗?”,这是一个奇怪的话题。但脚本绝对是一项有用的技能。
  • 强烈推荐pgplot。这是老派,但它有效。 astro.caltech.edu/~tjp/pgplot/gidriv.html

标签: plot gnuplot animated-gif


【解决方案1】:

您的数据是矩阵格式,您应该使用关键字matrix

问题是 gnuplot 想要 xy 坐标作为第一行第一列 (matrix nonuniform),或者两者都不想要。

要避免这种情况,您需要在第一行添加时间作为y 坐标,这并不难:

plot "< awk '{ print NR-1,$0}' file.dat" matrix nonuniform using 1:3:2 with l pal z

将为您提供不同颜色的每一行,例如

我认为标题中提到的gif动画问题应该单独提出,但可能this question结合以上就足够了。

【讨论】:

    【解决方案2】:

    我确信 OP 已经转移到其他方面,但是对于任何想知道您是否设法将数据保存在列中的人来说,所以第一列是 x 坐标,列 1,2....n 是相应的值您可以使用的每个时间步长

    set terminal gif animate delay 10
    set output 'solution.gif'
    stats "file.txt" matrix nooutput
    
    do for [i = 2:STATS_columns]{
        plot "file.txt" using 1:(column(i)) notitle with lines linestyle 1 
    }
    set output
    

    绘制数据并制作动画 gif。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-21
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多