使用if进行gnuplot条件绘图 [英] gnuplot conditional plotting with if

查看:264
本文介绍了使用if进行gnuplot条件绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两列的数据文件

I have a data file with two columns

10  0.5
20  0.8
25  0.3
15  0.6

如果第一列小于或等于20,我想绘制第二列.问题是,我想跳过第一列大于20的行,但是gnuplot迫使我在条件部分中做一些事情

I want to plot the second column if the first column is less than or equal 20. Problem is, I want to skip the rows where the first column is greater than 20, however gnuplot forces me to do something in the conditional part.

命令是

plot 'data.txt' u ($1<=20?$2:0) with points

如您所见,我必须指定一个零点.我不要那个!我想跳过......

As you can see, I have to specify to put a point of ZERO. I don't want that! I want to skip....

推荐答案

要跳过gnuplot中的某个点,您必须给它一个无效的值,例如1/0:

To skip a point in gnuplot you must give it an invalid value like 1/0:

plot 'data.txt' u 1:($1 <= 20 ? $2 : 1/0) with points

对于某些绘图样式,无效值的存在值得引起注意.是否应连接其余点用线表示,该线在无效点处中断.

For some plotting styles the presence of invalid values deserves some attention. If the remaining points should be connected e.g. with lines, the line is interrupted at an invalid point.

自gnuplot版本5.0.6起,您可以使用set datafile missing NaN来处理无效点,例如缺失点.然后,筛选出的数据的行为就好像无效点不存在一样.有关工作示例,请参见 https://stackoverflow.com/a/46070360/2604213 .

Since gnuplot version 5.0.6 one can use set datafile missing NaN to treat invalid points like missing ones. The filtered data then behaves as if the invalid points don't exist. See https://stackoverflow.com/a/46070360/2604213 for a working example.

这篇关于使用if进行gnuplot条件绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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