要Gnuplot通过指定参数直接使用(在 Linux Ubuntu 16.04 上)命令而不使用提示符,我输入以下示例:
gnuplot -e "filename='DataFile.txt'" SettingsFile
Run Code Online (Sandbox Code Playgroud)
哪里SettingsFile看起来像这样:
plot filename with lines
set title "Total Packets consumption"
set xlabel "Time"
set ylabel "Packets"
set datafile separator ","
pause -1
Run Code Online (Sandbox Code Playgroud)
看起来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
Run Code Online (Sandbox Code Playgroud)
第一个问题:
有没有办法将其设置为SettingsFilepng OutputFile ?因此我可以将其作为 Gnuplot 命令的参数输入,就像我对数据文件所做的那样。(我想这样使用它,因为我想从外部代码调用它)
我想实现这样的目标:
gnuplot -e "filename='DataFile.txt'" SettingsFile OutputFile.png
Run Code Online (Sandbox Code Playgroud)
第二个问题:
我从 Gnuplot 获得的屏幕输出显示 xtics 与预期不同:
另请注意,未显示轴标题!
现在,如果我尝试调整窗口大小,我会得到以下结果:
图表发生奇怪的翻转,标题设置和抽动根据需要更新。
我应该如何解决这两个问题,首先提到 SettingsFile 中的输出文件,其次 xtics 未正确显示,第三在屏幕输出中出现这种奇怪的行为?
可以通过分号添加多个命令gnuplot -e,例如:
gnuplot -p -e 'filename="data.txt"; fileout="image.png"' SettingsFile
Run Code Online (Sandbox Code Playgroud)
您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
Run Code Online (Sandbox Code Playgroud)
如果您想更好地控制代码,请尝试使用此脚本(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
Run Code Online (Sandbox Code Playgroud)
如果您想以交互方式绘制“DataFile.txt”(默认情况下):
gnuplot -p SettingsFile
Run Code Online (Sandbox Code Playgroud)如果你想绘制另一个文件,例如AnotherData.txt:
gnuplot -p -c SettingsFile AnotherData.txt
Run Code Online (Sandbox Code Playgroud)如果你想绘制另一个文件并将其另存为 PNG:
gnuplot -p -c SettingsFile AnotherData.txt Output.png
Run Code Online (Sandbox Code Playgroud)该-p参数让绘图窗口在主 gnuplot 程序退出后继续存在。Thw-c参数使用 gnuplot 的“调用”机制加载脚本,并将命令行的其余部分作为参数传递给它。请参阅如何将命令行参数传递给 gnuplot?
请注意,您的脚本首先绘制数据文件,然后配置标签、标题和datafile separator. 这就是为什么你会看到奇怪的抽动。
| 归档时间: |
|
| 查看次数: |
3063 次 |
| 最近记录: |