如何在 gnuplot 中从相同的标准输入数据绘制多个图?
我想要一个存储数据和 gnuplot 命令的 .plt 文件。我的数据看起来像
# x1 y1 x2 y2
1 2 3 4
5 6 7 8
并对应于两个图:(x1,y1) 和 (x2,y2)。
我知道我可以使用 "-"
,例如:
plot "-" using 1:2
# x1 y1 x2 y2
1 2 3 4
5 6 7 8
e
但这只会生成一个图,即 (x1,y1)。我正在尝试做类似的事情
plot "-" using 1:2, "-" using 3:4
# x1 y1 x2 y2
1 2 3 4
5 6 7 8
e
,但显然这不起作用,因为 gnuplot 需要来自第二个 "-"
的标准输入的一组新数据。
注意:
- 我无法更改数据的样式。它分为四列。
- 看来我可以通过
reread
来完成,但这需要两个文件。我真的只想要一个文件。
I want to have a single .plt file storing both data and gnuplot commands. My data looks like
# x1 y1 x2 y2
1 2 3 4
5 6 7 8
and corresponds to two plots: (x1,y1) and (x2,y2).
I know I can use "-"
like:
plot "-" using 1:2
# x1 y1 x2 y2
1 2 3 4
5 6 7 8
e
But that would generate only one plot, i.e., (x1,y1). I'm trying to do something like
plot "-" using 1:2, "-" using 3:4
# x1 y1 x2 y2
1 2 3 4
5 6 7 8
e
but obviously that doesn't work since gnuplot expects a new set of data from the standard input for the second "-"
.
Notes:
- I cannot change the style of the data. It comes in four columns.
- It seems that I can do it with
reread
but that requires two files. I really want only one file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果不修改输入数据的方式,您就无法做到这一点。当通过标准输入提供 gnuplot 数据时,它期望多个数据集之间用两个空行分隔,或者在连续行上交错。选项包括:
将两个数据集输入不同的数据集
完全绘制命令。
更改
文件格式,以便数据集具有
它们之间有空行,然后
使用索引引用它们。
更改文件格式,以便
交替的线代表不同的
数据集,然后引用它们
与每个。
将数据放入一个
文件,将绘图脚本放入
另一个,然后引用数据
使用不同的文件多次归档
每次using子句。
从 如何在单个文件中绘制多个数据集?这些是 gnuplot 中内置的用于此类事情的唯一设施,而且也不完全符合您的要求。很高兴您已经修改了数据格式,因为这永远不会像您最初希望的那样工作。
You can't do this without modifying something about the way you input the data. When feeding gnuplot data via standard input, it expects multiple data sets to be delimited with two blank lines between them, or to be interleaved on successive lines. The options are:
Feed the two data sets into different
plot commands altogether.
Change the
file format so that data sets have
blank lines between them, then
reference them all with index.
Change the file format so that
alternating lines represent different
data sets, then reference them all
with every.
Put the data into one
file, the plotting script into
another, and then reference the data
file more than once with different
using clauses each time.
There's an intro to the every and index commands starting at How do I plot several data sets in a single file? Those are the only facilities built into gnuplot for this sort of thing, and neither does exactly what you were asking about. it's good you've already modified the data formatting, because this wasn't ever going to work as you'd originally hoped.
我不确定你可以编辑多少文件,但最简洁的方法可能是将整个文件放入 shell 脚本/批处理脚本中(你在 Linux 还是 Windows 上?)
在 Linux 上我做了这样的事情
然后我 chmod +wrx 我将上述命令放入并运行的文件。
注意:这个问题似乎也有相似之处:
gnuplot stdin, how to绘制两条线?
所以你可能也想看看那里
I'm not sure how much you can edit the file, but the tidiest way is probably to put the whole thing in a shell script/batch script (are you on linux or windows?)
On linux I do something like this
Then I chmod +wrx the file I put the above commands in and run.
Note: there also seems to be a similarity to this question:
gnuplot stdin, how to plot two lines?
So you might want to look there too
自 gp5.0 以来的新选项(另请参阅
帮助内联数据
):New option since gp5.0 (see also
help inline data
) :我知道这是一篇旧帖子,但我想指出另一种策略,以防其他人仍然在解决这个问题:
您还可以使用绘图命令并输入数据两次,例如:
Gnuplot 实际上会等待两个块这个案例。当我不想更改命令以及通过管道输入 Gnuplot 时,我发现这非常有用。在实时场景中(取决于数据大小),这很可能仍然比缓冲到硬盘驱动器上的文件更快。
根据我的经验,缓冲脚本中的数据所需的代码量(需要多次通过管道传输)非常少。
I know this is an old post, but I would like to point to another strategy in case someone else still struggles with this issue:
You could also use your plotting command and input the data twice, like:
Gnuplot will actually wait for two blocks in this case. I find this very useful when I don't want to change the commands and when I am feeding Gnuplot by pipe. In a real-time scenario (depending on the data-size) this is very likely to be still faster than buffering to a file on the hard-drive.
In my experience the amount of code required to buffer the data in your script, which is required to pipe it more than once, is very low.