gnuplot:绘图命令中的变量值和定义

gnuplot: variable values and definitions in plot command

我偶然发现了以下内容:

根据 gnuplot 手册,绘图元素可能包含定义。

Syntax: 

      plot {<ranges>} <plot-element> {, <plot-element>, <plot-element>}

Each plot element consists of a definition, a function, or a data source 
together with optional properties or modifiers: 

      plot-element:
           {<iteration>}
           <definition> | {sampling-range} <function> | <data source>
                        | keyentry
           {axes <axes>} {<title-spec>}
           {with <style>}

检查以下示例:

为什么 gnuplot 忽略第二张图的 a=1? 我是不是误会了什么?

代码:

### definitions in plot command
reset session

a = 1
b = 1
f(x) = a*x + b

set yrange[-40:40]
set multiplot layout 1,3
    plot     f(x)
    plot     f(x), a=2 f(x), a=3 f(x)
    plot a=1 f(x), a=2 f(x), a=3 f(x)
unset multiplot
### end of code

结果:

您的诊断略有偏差。在第二个面板中,第一个紫色图与 a=3 图而不是 a=2 图叠加。

为什么?因为 gnuplot 在实际绘制任何元素之前会累积完整图的所有元素。这涉及通过命令行进行两次传递。第一次通过分析和加载来自任何提到的数据源的数据(例如自动缩放需要),然后第二次通过评估范围内的任何函数(这可能由自动缩放确定)。在这里的第一遍中,a 被设置为 2,然后设置为 3。在第二遍开始时,a 仍然是 3,并且在没有初始定义来更改它的情况下,这就是计算 f(x) 时使用的值.