如何在同一图上绘制两个数据列,其中x轴由文件行号暗示(使用gnuplot) [英] how can I plot two colums of data on the same plot where the x axis is implied by the file row number (using gnuplot)

查看:38
本文介绍了如何在同一图上绘制两个数据列,其中x轴由文件行号暗示(使用gnuplot)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两列数字的文本文件,我将其称为col1和col2.我可以使用gnuplot来绘制col2与col1的关系,反之亦然,但是我无法弄清楚如何根据文件中的行号来绘制col1和col2(即覆盖数据的两列)也就是说,x轴由文件行编号隐式给出.我想我可以在第一列中插入行号,但是我猜想在gnuplot中有一种更简单的方法可以做到这一点.在Linux中,我可以使用"cat -n"可以输出三列文件,但是我正试图在Windows系统上为一个朋友做这个,我不知道Windows是否有类似的东西.

I have text files containing two columns of numbers which I'll call col1 and col2. I'm able to use gnuplot to plot col2 versus col1 or vice-versa but I can't figure out how to plot both col1 and col2 (i.e., overlay both columns of data) as a function of the row number in the file (i.e., the x axis is given implicitly by the file row numbering). I suppose I could insert a row number into column one but I'm guessing there is an easier way to do this in gnuplot. In linux I could use "cat -n" to output a three column file but I'm trying to do this on a Windows system for a friend and I don't know if Windows has something akin to cat.

谢谢!

推荐答案

仅用于记录.不管您认为是行号...在大多数情况下,伪列0(请检查 help伪列)可以完成此任务.但是,如果您的数据中有两个空行,则情况将有所不同,因为伪列0将被重置为 0 .请检查以下示例,以说明伪列0与您自己计算行数的另一种方法之间的区别.

Just for the records. Whatever you consider as line number... In most cases the pseudocolumn 0 (check help pseudocolumns) will do the job. However, if you have double empty lines in your data the situation will look different, because the pseudocolumn 0 will be reset to 0. Check the following example to illustrate the difference between pseudocolumn 0 and another approach counting the lines yourself.

代码:

### plotting data versus "line number"
reset session

$Data <<EOD
 1   21
 2   22
 3   23

 5   24
 6   25
 7   26


10   27
11   28
12   29
EOD

set multiplot layout 1,2

    plot $Data u 0:2 w lp pt 7

    plot n=0 $Data u (n=n+1):2 w lp pt 7

unset multiplot
### end of code

结果:

这篇关于如何在同一图上绘制两个数据列,其中x轴由文件行号暗示(使用gnuplot)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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