gpt4 book ai didi

linux - 在没有提示的情况下使用 gnuplot 命令

转载 作者:太空狗 更新时间:2023-10-29 11:50:03 24 4
gpt4 key购买 nike

要通过指定参数直接使用 Gnuplot(在 linux Ubuntu 16.04 上)命令而不使用它的提示,我输入这个例子:

gnuplot -e "filename='DataFile.txt'" SettingsFile

SettingsFile 看起来像这样:

plot filename with lines
set title "Total Packets consumption"
set xlabel "Time"
set ylabel "Packets"
set datafile separator ","
pause -1

DataFile.txt 如下所示:

数据包,时间(以秒为单位):

13392,120
24607,240
23867,360
21764,480
20727,600
20004,720
19719,840
19758,960
19728,1080
20168,1200
19737,1320
19729,1440
20135,1560
20006,1680
21301,1800
19923,1920
20002,2040
19761,2160
20918,2280
22756,2400
22820,2520
23370,2640
22987,2760
22956,2880
24427,3000
23527,3120
24009,3240
23832,3360
23464,3480
23652,3600
11212,3654

第一个问题:

有没有办法在 SettingsFile 中设置一个 png OutputFile?所以我可以将它作为 Gnuplot 命令的参数输入,就像我对 DataFile 所做的那样。 (我想这样使用它,因为我想从外部代码调用它)

我想实现这样的目标:

gnuplot -e "filename='DataFile.txt'" SettingsFile OutputFile.png 

第二个问题:

我从 Gnuplot 获得的屏幕输出显示 xtics 与预期不同:

enter image description here

另请注意,轴标题未显示!

现在,如果我尝试调整窗口大小,我会得到:

enter image description here

图形奇怪地翻转,标题设置和抽动根据需要更新。

我应该如何解决这两个问题,首先是在 SettingsFile 中提到一个输出文件,其次是 xtics 没有正确显示,第三个是屏幕输出中的这种奇怪行为?

最佳答案

可以通过分号在gnuplot -e中加入几个命令,例如:

gnuplot -p -e 'filename="data.txt"; fileout="image.png"' SettingsFile

您的 SettingsFile 应该已经有一行配置终端类型:

set terminal png
set output fileout

set title "Total Packets consumption"
set xlabel "Time"
set ylabel "Packets"
set datafile separator ","

plot filename using 2:1 with lines

如果你想更好地控制你的代码,试试这个脚本(gnuplot 5.0+):

filename=(ARGC>0 ? ARG1 : 'DataFile.txt' )  # By default filename=DataFile.txt
# If called with one argument (ARGC=1)
# then `filename=ARG1`

if(ARGC>1){
# if called with two arguments (ARGC=2), then configure a png output
set terminal png
set output ARG2
}

set title "Total Packets consumption"
set xlabel "Time"
set ylabel "Packets"
set datafile separator ","

# the plot command ALWAYS at the end of the script after the settings
plot filename using 2:1 with lines
  • 如果您想以交互方式绘制“DataFile.txt”(默认情况下):

    gnuplot -p SettingsFile
  • 如果你想绘制另一个文件,例如AnotherData.txt:

    gnuplot -p -c SettingsFile AnotherData.txt
  • 如果您想绘制另一个文件并将其另存为 PNG:

    gnuplot -p -c SettingsFile AnotherData.txt Output.png

-p 参数让绘图窗口在主 gnuplot 程序退出后继续存在。 Thw -c 参数使用 gnuplot 的“调用”机制加载脚本,并将命令行的其余部分作为参数传递给它。参见 How to pass command line argument to gnuplot?

请注意,您的脚本首先绘制数据文件,然后配置标签、标题和数据文件分隔符。这就是为什么您会看到奇怪的抽动。

关于linux - 在没有提示的情况下使用 gnuplot 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41795979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com