linux下如何运行gnuplot脚本,了解gnuplot如何使用awk脚本

本文探讨了如何在gnuplot中使用awk脚本,并比较了直接使用awk和通过bash脚本调用awk执行plot和load命令的区别。作者揭示了`load`命令对输入文件的特殊要求,以及为何script.sh方法不生效,提供了相关命令语法和示例帮助理解gnuplot的工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我有一个数据文件

data.txt中

1 1

2 2

3 3

5 4

7 5

我试图了解gnuplot如何使用awk.我可以用情节“< awk'{print $1,$2}'data.txt”绘制它.但是,当我尝试加载'< ./ script.sh data.txt'时,它不起作用. script.sh

#!/bin/bash

awk 'BEGIN {

printf "plot ";

}

{

printf "%i %i\n",$1,$2

}

' $1

使用script.sh方法返回错误:

gnuplot> plot 1 1

06002

“<. data.txt line unexpected or unrecognized token>

在我看来,我的awk脚本是内联awk语句的功能等价物.为什么script.sh方法不起作用?

仅供参考,我知道我可以用“data.txt”u 1:2来绘制我的数据.这只是我想要解决的更复杂问题的理想化版本.

这应该与awk无关,但是对于plot和load命令都有gnuplots期望.

在我的理解中阅读gnuplot帮助输出并尝试您提供的示例:

plot "

只是一种复杂的方式,通过popen调用在你的系统上提供一个像object这样的文件,plot命令然后从x,y点读取.

你的第二个脚本做了一些不同的事情,因为load命令现在在第一行接收一个它不能满足的命令(即绘图后跟一个x和y值),即使没有任何前缀命令也会收到后续命令(下一行只是2在这种情况下为2.

在我的活动gnuplot使用的记忆中 – 几年前,如果不是几十年;-) – 加载就像加载,你可以从模块组成绘图代码,但这些必须包含有效的gnuplot命令.

我系统上的加载帮助给出了:

gnuplot> help load

The `load` command executes each line of the specified input file as if it

had been typed in interactively. Files created by the `save` command can

later be `load`ed. Any text file containing valid commands can be created

and then executed by the `load` command. Files being `load`ed may themselves

contain `load` or `call` commands. See `comments` for information about

comments in commands. To `load` with arguments, see `call`.

Syntax:

load ""

The name of the input file must be enclosed in quotes.

The special filename "-" may be used to `load` commands from standard input.

This allows a `gnuplot` command file to accept some commands from standard

input. Please see help for `batch/interactive` for more details.

On some systems which support a popen function (Unix), the load file can be

read from a pipe by starting the file name with a '

Examples:

load 'work.gnu'

load "func.dat"

load "< loadfile_generator.sh"

The `load` command is performed implicitly on any file names given as

arguments to `gnuplot`. These are loaded in the order specified, and

then `gnuplot` exits.

我总是解决了生成匹配文件的问题,并为gnuplot调用提供了一些调用魔法来参数化这些图.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值