How to plot a specific subset of data from a data file with gnuplot?

跟風遠走 提交于 2020-01-06 03:08:06

问题


I need to plot a single point, from a line in data file, that has many other lines and two rows. I don't know how to select a single line in gnuplot, not the entire file of data. Any suggestions please???


回答1:


You have to filter out. In gnuplot this is done with the keyword every.

Since you do not provide the file you want to plot here is a possible hint based on this datafile data.dat:

10 62
11 95
12 74
13 33
14 70

youplot the point at the third line (12,74) like this:

plot 'data.dat' every ::2::2 w p

based on the file structure, this might vary.

Maybe if you have to do it several times it's good to set a variable:

n=2
plot 'data.dat' every ::n::n w p

so that once plotted, you can do:

n=3; replot
n=10; replot
...

Please read carefully the help every command in gnuplot




回答2:


In case the point(s) you want to plot are not characterized by the line number, but by some value in one column, you can use this trick in using :

plot '-' using (($1==0)?$1:1/0):2 with points
-1 1
0  2
1  3
e

This can be used to plot e.g. only points with a positive x-coordinate (change to ($1>=0)?$1:1/0), or also, using the $0 pseudo-column which contains the line number, to select specific lines in a more versatile way than every :

plot 'data.dat' using (((int($0)%3!=0)?$1:1/0):2 with points

Here we plot 2 lines out of 3, of course you can also select one line only with ($0==LINE)?$1:1/0.



来源:https://stackoverflow.com/questions/36926994/how-to-plot-a-specific-subset-of-data-from-a-data-file-with-gnuplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!