gnuplot: Faulty sensor sometimes reading 0.00 - how to convert them to missing?

北城余情 提交于 2019-12-02 12:07:05

问题


I have a combination RPi/Arduino taking readings from several DHT-22 Humidity/Temperature sensors.

One of the sensors developed a loose wire and has been giving occasional 0.00 temperature readings for 10-20 minutes in a row. Because of the other data collected at the same time I don't really have the option to just delete the whole line of data like I would if it were the only sensor being recorded. The wire has been fixed now.

So my question is, can I do something in the gnuplot code to consider those 0.00 values as simply missing for the plot so it could ignore them?


回答1:


Gnuplot allows you to filter data while plotting:

gnuplot 'file.dat' using 1:($2 == 0.0 ? 1/0 : $2)

This treats all values of 0 as invalid points and those points are skipped. Depending on the selected plotting style that works, or not: plot ... with lines interrupts a line at an invalid point.

Since gnuplot version 5.0.6 you can use set datafile missing NaN to have invalid points treated as missing ones, and a line would simply ignore those points:

$data <<EOD
12
27
0
23
42
EOD

set multiplot layout 1,2

set title '0.0 invalid'
plot $data using 0:($1 == 0.0 ? 1/0 : $1) with linespoints pt 7 notitle

set title '0.0 invalid but treated as missing'
set datafile missing NaN
replot

unset multiplot

Output with 5.0.6:



来源:https://stackoverflow.com/questions/43990540/gnuplot-faulty-sensor-sometimes-reading-0-00-how-to-convert-them-to-missing

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