如何使用gnuplot进行条件绘图 [英] How to use gnuplot to do conditional plot

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

问题描述

我是gnuplot的新手,很难弄清楚如何做条件图.

我有一个数据文件,我想绘制第一列和第二列的数据以生成折线图,并保存到JPEG/PNG文件中.

test.txt

1 9.9999 0
2 9.9999 0
3 9.9999 1
4 5.6000 0
5 3.4000 0
6 9.9999 1

我要做的是从此数据文件中绘制第1列和第2列,当第2列的值为9.9999时,将该值设置为0.这意味着每当发生9.9999时,在图表中显示为0. /p>

这是我正在使用的代码,但似乎不起作用.

plot 'test.txt'  using 1:($2==9.99999?0:$2) with linespoint title 'test'

解决方案

除了要比较的数字不正确外,比较浮点数是否相等通常是有问题的.

想到类似的东西

 plot 'test.txt'  using 1:(abs($2-9.9999)<0.1?0:$2) with linespoint title 'test'

I am new to gnuplot and having a hard time to figure how to do conditional plot.

I have a data file, and I want to plot the data from 1st and 2nd columns to generate a line chart, save to JPEG/PNG file.

test.txt

1 9.9999 0
2 9.9999 0
3 9.9999 1
4 5.6000 0
5 3.4000 0
6 9.9999 1

What I want to do is plot 1st and 2nd column form this data file, when the value of 2nd column is 9.9999, then set the value to 0. That means whenever 9.9999 happens, it shows as 0 in the chart.

This is the code I am using, but seems doesn't work.

plot 'test.txt'  using 1:($2==9.99999?0:$2) with linespoint title 'test'

解决方案

In addition to the incorrect number you're comparing with, it is usual problematic to compare floating point numbers for equality.

Think of something like

 plot 'test.txt'  using 1:(abs($2-9.9999)<0.1?0:$2) with linespoint title 'test'

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

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