在 gnuplot 中使用多个变量绘图

Ove*_*lex 3 variables plot gnuplot

我有一个包含多列的数据文件,前两列表示位置,其他表示其他属性(例如从这里发送的项目数)。例如:

1  1  1  57.11
2  1  2  62.40
3  4  1  31.92
Run Code Online (Sandbox Code Playgroud)

我想要做的是在位置绘制点,但使用其他列中的值来改变点类型和大小(例如)。但是我似乎找不到引用图中列的方法。我知道“变量”的用法,但我找不到使用多个变量的方法。

我想要的是以下内容:

plot "mydata" using 1:2 notitle with points pt ($3) ps ($4/10)
Run Code Online (Sandbox Code Playgroud)

以便 pt 和 ps 分别使用从第三列和第四列中获取的每个点的值。

这在 gnuplot 中甚至可能吗?是否有某种解决方法?

mgi*_*son 5

你应该能够使用关键字variable来做这样的事情:

plot 'datafile' using 1:2:3:4 w points ps variable lc variable
Run Code Online (Sandbox Code Playgroud)

或者可能将值映射到调色板:

plot 'datafile' using 1:2:3:4 w points ps variable lc palette
Run Code Online (Sandbox Code Playgroud)

关键字变量和/或调色板导致 gnuplot 从文件中读取属性,并且它们都需要通过using. 当然,使用的所有常用东西都适用 - 您可以将转换应用于数据等:

plot 'datafile' using 1:2:3:($4+32.) w points ps variable lc palette
Run Code Online (Sandbox Code Playgroud)

我不记得第 3 列是这里的点大小还是颜色,我现在没有时间玩弄它来弄清楚。您可以进行实验并发表评论,或者当我有时间时会回到这里并添加更新。


其他一些属性(例如pointtype)不能很容易地更改为使用variable. 最简单的方法是使用带有 gnuplot 三元运算符的过滤器。

首先,编写一个函数,该函数根据数据文件的 1 列中的数据返回一个点类型:

my_point_type(x) = x   
Run Code Online (Sandbox Code Playgroud)

这里我使用了一个简单的标识函数,但它可以是任何东西。现在,您可以遍历所需的点类型(此处为 1-10),为每个点类型绘制一个图:

plot [for PT=1:10] 'datafile' u 1:((my_point_type($3) == PT) ? $2:NaN) with points pt PT
Run Code Online (Sandbox Code Playgroud)

这假设具有点类型信息的列是第三列,第二列保存位置信息。这也可以与我上面演示的内容相结合。