如何在gnuplot中使用`set term push`和`set term pop` [英] How to use `set term push` and `set term pop` in gnuplot

查看:51
本文介绍了如何在gnuplot中使用`set term push`和`set term pop`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Arch Linux上使用gnuplot 5.2.7.我想临时更改终端的配置,绘制某些内容,然后还原它(初始化文件中没有终端配置).我认为 pop push 可以达到这种效果,但是我没有成功.

I am using gnuplot 5.2.7 on Arch Linux. I want to temporarily change the terminal's configuration, plot something, and then restore it (I have no terminal configuration in my initialization file). I think pop and push can be used to this effect, but I'm having no success.

这是我在gnuplot会话中所做的.首先,将终端设置为 wxt 并推动它,然后绘制正弦波:

This is what I do in a gnuplot session. First I set the terminal to wxt and push it, then plot a sine wave:

gnuplot> set term wxt 1 ; set term push

Terminal type is now 'wxt'
Options are '1 enhanced'
   pushed terminal wxt 1 enhanced
gnuplot> plot sin(x)

到目前为止,这是可行的.现在,我想暂时将背景更改为青色,然后恢复为默认背景:

So far this works. Now I want to temporarily change the background to cyan, and then revert to default background:

gnuplot> set term wxt 1 background "cyan"

Terminal type is now 'wxt'
Options are '1 background '#00ffff' enhanced'
gnuplot> plot sin(x)
gnuplot> set term pop
   restored terminal is wxt 1 background '#00ffff' enhanced
gnuplot> 

如您所见,对终端进行 pop 并没有恢复背景.下一个情节带有青色背景.

As you can see, poping the terminal didn't restore the background. The next plot comes up with a cyan background.

Gnuplot的手册(pdf)在第257页中指出:

Gnuplot's manual (pdf) states, in page 257, that:

命令 set term push 会记住当前终端,包括其设置,而设置术语弹出会恢复它.

The command set term push remembers the current terminal including its settings while set term pop restores it.

我在做什么错了?

推荐答案

来自gnuplot手册:

From the gnuplot manual:

命令集术语push会记住当前终端,包括其设置术语弹出时恢复设置.这相当于保存条件和负载条件,但不访问文件系统.所以它们可用于实现平台的独立还原例如,打印后的终端.gnuplot启动后,默认终端或启动文件中的终端会自动推送.因此,可移植脚本可以依靠设置的术语pop来恢复给定平台上的默认终端,除非已使用另一个终端明确推送.

The command set term push remembers the current terminal including its settings while set term pop restores it. This is equivalent to save term and load term, but without accessing the filesystem. Therefore they can be used to achieve platform independent restoring of the terminal after printing, for instance. After gnuplot's startup, the default terminal or that from startup file is pushed automatically. Therefore portable scripts can rely that set term pop restores the default terminal on a given platform unless another terminal has been pushed explicitly.

实际上,我尚不完全清楚 terminal push terminal pop 有什么好处?好了,还原默认终端.我能(当前)想到的唯一好处是,在长的gnuplot脚本中,当您来回切换到不同的终端时,不必一次又一次地键入默认终端的所有参数.而且,如果您更改了某些终端设置,则必须更改脚本中所有出现的内容.

Actually, it's not completely clear to me what is the benefit of terminal push and terminal pop? Well, restoring the default terminal. The only advantage I can (currently) think of is that in a long gnuplot script when you are switching back and forth to different terminals you don't have to type in all the parameters of your default terminal again and again. And in case you change some terminal settings you otherwise would have to change all the occurrences in your script.

以下内容可能对您有用:在代码的开头,将具有背景或其他设置的终端定义为字符串变量,然后使用 @ 将其称为宏.因此,在此看来,调用 @TerminalDefault set terminal pop 之间没有区别,除了 @TerminalDefault 也会在您恢复时之前具有相同的终端,但设置不同.

Maybe the following is useful to you: at the beginning of the code define your terminals with your backgrounds or other settings as string variables and then later call them as macro with @. So with this, I don't see a difference between calling @TerminalDefault and set terminal pop, except that @TerminalDefault will also restore if you had the same terminal before but just with different settings.

代码:

### workaround for terminal push & pop with same terminal but different settings
reset session

TerminalDefault = 'set term wxt 0 background "white"'
TerminalCyan = 'set term wxt 0 background "cyan"'
TerminalYellow = 'set term wxt 0 background "yellow"'
TerminalPNG = 'set term png background "green"'

@TerminalDefault
plot x
pause -1 TerminalDefault

@TerminalCyan
plot x**2
pause -1 TerminalCyan

@TerminalPNG
set output "Test.png"
plot x**3
set output
pause -1 TerminalPNG

@TerminalDefault
plot x**4
pause -1 TerminalDefault

### end of code

这篇关于如何在gnuplot中使用`set term push`和`set term pop`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆