【问题标题】:Script Gnuplot on windows OS在 Windows 操作系统上编写 Gnuplot 脚本
【发布时间】:2023-03-08 07:54:01
【问题描述】:

我想从数据文件列表中自动生成图表。

更多细节: 我有一个包含我所有数据文件的目录。我需要为每个文件(数百个)生成一个图表。我有一个 gnuplot 文件来生成一个图形,但数据文件的名称在 gnuplot 脚本中指定。

例如:

plot 'myfile' index 1  using 1:2 with linespoints pointtype 2 linecolor rgb "green"  title "leg"

我需要能够将“myfile”替换为可以在我目录的所有文件上迭代的变量名。

【问题讨论】:

    标签: windows bash automation gnuplot


    【解决方案1】:

    您可以使用以下命令创建一个 (Windows) 批处理文件:

    for %%G in (*.dat) do gnuplot.exe -e "fn='%%G'" script
    

    这将为当前目录中的每个 .dat 文件运行 gnuplot(和 脚本)。

    -e 开关用于input variables via command line(此处为文件名,如果包含空格,请用引号括起来)。

    如果您想直接从 shell(而不是在批处理文件中)运行此命令,请从两对中的每一对中删除一个 % 符号。

    在脚本文件中:

    plot fn index 1  using 1:2 with linespoints pointtype 2 linecolor rgb "green"  title "leg"
    

    如果数据文件具有“标准化”名称(例如 data1.datdata2.dat...),请查看 https://stackoverflow.com/a/14947085/3235496

    【讨论】:

      【解决方案2】:

      一般来说,您可以在 gnuplot 中迭代许多文件,如下所示:

      set terminal pdfcairo
      list = "fileA fileB fileC"
      
      do for [file in list] {
          set output file . '.pdf'
          plot file
      }
      

      这种迭代至少需要 4.6.0 版本。在此示例中,您有一个固定的文件名列表(这些文件名不允许包含空格)。

      在 Windows 上你可以使用

      list = system('dir /b *.txt')
      

      获取包含当前目录中所有.txt 文件的列表。请注意,您必须使用 wgnuplot_pipes.exe 才能使其正常工作。

      在 Unix 系统上你可以使用

      list = system('ls *.txt')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-29
        • 1970-01-01
        • 2023-03-12
        • 2020-02-10
        • 1970-01-01
        • 1970-01-01
        • 2020-03-09
        • 1970-01-01
        相关资源
        最近更新 更多