使用gnuplot根据列值绘制多个图形 [英] Plotting multiple graphs depending on column value with gnuplot

查看:110
本文介绍了使用gnuplot根据列值绘制多个图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据,我无法使用GNUPLOT进行绘制:

I have the following data, which I wan't to plot using GNUPLOT:

#TIME #VALUE #SOURCE
1 100 A
1 88 B
2 115 A
2 100 B
3 130 A
3 210 B

我希望绘制两行,具体取决于#SOURCE列的值. A 一行, B 一行. GNUPLOT是否可行?如果是,怎么办?

I want to have two lines drawn, depending on the value of column #SOURCE. One line for A and one line for B. Is this possible with GNUPLOT and if yes how?

是否有可能根据#TIME列得出#VALUE列的总和?意思是,对于#TIME中所有相等的条目,将对#VALUE中的值求和.

Is it possible to also draw a summation of column #VALUE depending over column #TIME? Means, that for all equal entries in #TIME, the values in #VALUE will be summed up.

预先感谢, 弗兰克

推荐答案

一种方法是使用grep定位以AB结尾的行并绘制结果.如果您知道字符行将以以下结尾,则可以在带有for循环的单个绘图行中完成此操作:

One way to do it would be to use grep to locate lines ending with A or B and plot the result. You can do this in a single plot line with a for loop if you know the characters lines will end in:

plot for [s in 'A B'] sprintf("<(grep -v '%s$' data.dat)", s) u 1:2 w l

这会将您提供的数据(保存在data.dat中)绘制为两条不同的线.

This plots the data you provided (saved in data.dat) as two different lines.

您也可以将for部分更改为[s in 'word1 word2 word3']或您喜欢的任何其他字符串.如果您不知道字符/单词行将以结尾,则可能需要先两次传递文件以确定for循环的字符串,然后第二次进行绘制.

You could also change the for part to [s in 'word1 word2 word3'] or any other string you like. If you don't know the character/word lines will be ending with you would probably need to pass the file twice first to determine the string for the for loop and a second time to do the plotting.

这篇关于使用gnuplot根据列值绘制多个图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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