对于gnuplot终端中的多个命令,用户定义的命令,如gdb&s;定义?

时间:2013-01-23 05:20:08

标签: gnuplot

以为我会记录这个(自我回答):

在终端中使用gnuplot时,可以使用键盘上的向上和向下箭头来迭代键入的命令历史记录 - 就像在gdb中一样。

然而,有时可能会有一系列我经常重复的命令 - 我想通过发出一个命令来调用它。例如,一个使用x11中的交互式gnuplot终端,并希望以png格式获取“屏幕截图”。这需要将终端更改为png,设置输出,发布plot,终端恢复为x11;或者:

set terminal png
set output 'gnuplot.png'
replot
set terminal x11

我希望用一个命令调用这个序列 - 即使我知道这些序列可以放在一行上,使用分号作为分隔符:

set terminal png ; set output 'gnuplot.png' ; replot ; set terminal x11

gdb中,有一个命令define,允许user-defined commands;一个只是在gdb终端发布:

(gdb) define fn
> finish
> next
> end

...从那时起,可以在该终端输入fn来调用finishend的序列。

是否有与gnuplot类似的内容?

1 个答案:

答案 0 :(得分:1)

是的,似乎有 - 在help macros)中有一个名为macros(gnuplot)的工具,其中可以通过添加@(“at”字符)来扩展字符串变量)以它的名字命名。

默认情况下禁用此工具,因此需要考虑启用它。这就是为什么最好将该序列保存在init脚本文件中,例如init.gp命名:

print ""
print "init.gp starting"

set terminal x11

# define capt string variable as sequence
# of commands, semicolon separated

capt = "print 'Saving...' ; set terminal png ; set output 'gnuplot.png' ; replot ; set terminal x11"

print "macros state: "
show macros

print "enabling macros state:"
set macros
show macros

print "The @capt command should be available now."
print ""
print "init.gp ending"
print ""

然后可以在gnuplot中执行这样的终端会话:

$ gnuplot

    G N U P L O T
    [...]

Terminal type set to 'wxt'

gnuplot> load "init.gp"

init.gp starting
macros state: 

    command line macros will not be expanded

enabling macros state:

    command line macros will be expanded

The @capt command should be available now.

init.gp ending

gnuplot> plot sin(x)

gnuplot> @capt
Saving...
Terminal type set to 'png'
Options are 'nocrop font /usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf 12 size 640,480 '
Terminal type set to 'x11'
Options are ' nopersist'

gnuplot> plot cos(x)
Closing gnuplot.png

gnuplot> exit

$ identify gnuplot.png 
gnuplot.png PNG 640x480 640x480+0+0 8-bit PseudoClass 102c 5.58KB 0.000u 0:00.000

嗯,希望这有助于某人,
干杯!

相关问题