【问题标题】:GNUPLOT: Follow command to the next line?GNUPLOT:跟随命令到下一行?
【发布时间】:2020-05-05 20:49:55
【问题描述】:

我有一个名为 tmp.plt 的 gnuplot 脚本:

plot \
"n300_50int/ini-ene.his" using 1:2, \ 
"n500_100int/ini-ene.his" using 1:2, \ 
"n500_1ooint_0.65e3/ini-ene.his" using 1:2, \ 
"n500_50int/ini-ene.his" using 1:2

但它给了我错误

samuel@samuel-P5Wx6~/Documents/Fisica/19-20/Radiactividad/Prácticas/Practicas-MontCarlo/PET/Simulaciones$ gnuplot -p tmp. plt

使用 1:2 绘制“n300_50int/ini-ene.his”,\
                                         ^
“tmp.plt”,第 2 行:无效字符 \

我使用以下 .sh 创建了这个脚本(从 Gnuplot: Plot several in files in different folders 中的那个编辑):

#!/bin/bash

## truncate tmp.plt and set line style
echo -e "plot \\" > tmp.plt

cnt=0   ## flag for adding ', \' line ending

## loop over each file
for i in */ini-ene.his; do
    if ((cnt == 0)); then       
        cnt=1                   
    else
        printf ", \\ \n" >> tmp.plt             
    fi
    printf "\"$i\" using 1:2" >> tmp.plt 
done
echo "" >> tmp.plt              

我不明白为什么当下一个 test.plt 文件运行时它不起作用

f(x)=x
g(x)=2*x
plot \
f(x) , \
g(x)

谢谢!

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    由于tmp.plt 文件中的反斜杠 (\) 导致出错。原因是\ 必须是根据gnuplot 指令的行中的最后一个字符。在非工作示例中,\ 后面有一个空格。如果您在工作示例中的\ 之后添加一个空格,它也会出错。如图所示:

    plot f(x) , \ 
                ^
    "test.plt" line 4: invalid character \
    

    所以试试: printf ",\\\n" >> tmp.plt(或只是printf ",\n" >> tmp.plt

    而不是: printf ", \\ \n" >> tmp.plt

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-18
    • 2021-06-28
    • 2017-03-13
    相关资源
    最近更新 更多