将文件从 bash 脚本传递到 gnuplot 脚本

yas*_*ink 5 scripts input gnuplot

我是 gnuplot 的新手,我在传递我的论点时遇到了很多麻烦,现在我有了这个简单的 bash 脚本和一个 gnuplot 脚本。

在 bash 脚本中,plot.sh我应该修改我的文件,然后将其发送到要绘制的 gnuplot 脚本,或者我可以修改我的文件,然后将一个参数(从另一个脚本 $1 传递的数字)发送到 gnuplot 脚本,该脚本标识要绘制的文件,问题是这两种方式都不起作用,我似乎没弄对!有什么帮助吗?

这是我的 bash 脚本 plot.sh

#!/bin/bash

sed -i 's/ns/;/g' /dev/shm/waitingTime$1.txt
gnuplot -e "filename='/dev/shm/waitingTime$1'" file.gnuplot
Run Code Online (Sandbox Code Playgroud)

这是我的名为 file.gnuplot 的 gnuplot 脚本

#!/home/yas/file.gnuplot

set xlabel "start"    
set ylabel "Delay"
set autoscale
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
plot<"filename"> using 1:2 w points title "tests"
set terminal postscript portrait enhanced mono dashed lw 1 'Helvetica' 14
set output '/dev/shm/TT.pdf'
pause -1
Run Code Online (Sandbox Code Playgroud)

文件结尾.gnuplot

Rma*_*ano 2

如果我理解正确的话,您希望图表显示在显示屏上,然后在 PDF 文件中拥有一个副本/dev/shm/TT.pdf

我在这里看到两个问题:

  1. 绘图的说明 --- 您将文件名存储在 中filename,所以 ypu 应该说

    plot filename  using 1:2 w points title "tests"
    
    Run Code Online (Sandbox Code Playgroud)

    没有<"……的东西。

  2. 如果您想要 pdf 文件,您应该replot在更改终端和输出文件后添加一个(仔细检查您可以在目标目录中写入)。

我创建了一个文件data.dat和该文件file.gnuplot

set xlabel "start"    
set ylabel "Delay"
set autoscale
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
plot filename   using 1:2 w points title "tests"
set terminal postscript portrait enhanced mono dashed lw 1 'Helvetica' 14
set output 'TT.pdf'
replot
pause -1
Run Code Online (Sandbox Code Playgroud)

并用以下方式调用它:

gnuplot -e "filename='data.dat'" file.gnuplot 
Run Code Online (Sandbox Code Playgroud)

我有输出:

在此输入图像描述

...以及相应的TT.pdf文件。

顺便说一句,pause我发现最好添加而不是在最后添加

set terminal wxt persist 
Run Code Online (Sandbox Code Playgroud)

在开始处,并删除暂停。脚本将自然完成,并且带有图形的窗口将保持不变,直到您将其关闭。