I am trying to plot data from a file, using pgfplots for the plot and pgfplotstable to read in the data and calculate a new column (cummulative values from another row), which is plotted as well. My data sometimes has bad values (negative values when all values should be non-negative) and I would like to filter those values from the plot and the calculation, either by ignoring them or setting them to zero. pgfplots has a convenient filter option for the plots, but this has no effect on the calculated column.
Here's a MWE of what I am trying to accomplish. There should not be any negative values in the plots. How should I filter the values?
\documentclass{minimal}
\usepackage{filecontents}
\begin{filecontents}{data.csv}
Time,TemperatureC,DewpointC,PressurehPa,WindDirection,WindDirectionDegrees,WindSpeedKMH,WindSpeedGustKMH,Humidity,HourlyPrecipMM,Conditions,Clouds,dailyrainMM,SoftwareType,DateUTC,
2012-10-26 00:51:00,26.9,26.1,1009.4,SSE,163,8.0,22.5,95,0.0,,,0.0,weatherlink.com 1.10,2012-10-26 04:51:00,
2012-10-26 01:06:00,26.9,26.1,1009.0,SW,231,8.0,20.9,94,0.0,,,0.0,weatherlink.com 1.10,2012-10-26 05:06:00,
2012-10-26 01:21:00,26.9,26.1,1009.0,SSE,151,14.5,-1607.4,94,-2539.7,,,0.0,weatherlink.com 1.10,2012-10-26 05:21:00,
2012-10-26 01:36:00,27.0,26.1,1009.0,SSE,155,4.8,22.5,93,0.0,,,0.0,weatherlink.com 1.10,2012-10-26 05:36:00,
2012-10-26 01:51:00,27.1,26.1,1009.4,South,174,6.4,19.3,93,0.0,,,0.0,weatherlink.com 1.10,2012,
\end{filecontents}
% UNITS
\usepackage{siunitx}
% PGFPLOTS and TABLES
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{
width=10cm,
compat=1.7}
\usepgfplotslibrary{dateplot}
\usepgfplotslibrary{groupplots}
\usepackage{pgfplotstable}
\pgfplotstableset{
col sep=comma,
create on use/SumP/.style={
create col/expr={\pgfmathaccuma + \thisrow{HourlyPrecipMM}}
}
}
% ------------------------------------------------- Document starts here
\begin{document}
\pgfplotstableread{data.csv}\data
\begin{tikzpicture}
\begin{groupplot}[
group style={%
group size=1 by 2,
horizontal sep=0pt,
vertical sep=10pt,
xticklabels at=edge bottom,
xlabels at=edge bottom,
ylabels at=edge left,
},
legend style={draw=none},
legend pos=north west,
legend cell align=left,
date coordinates in=x,
xtick=,
xticklabel style={rotate=90,anchor=near xticklabel},
xticklabel=\month-\day. \hour:\minute,
date ZERO=2012-10-23,
minor tick num=12,
footnotesize,
width=10cm,
xlabel=Time / \si{\hour},
ylabel=P / \si{\mm},
ybar
]
\nextgroupplot[]
\addplot+[const plot mark left,fill=none] table[x=Time,y=HourlyPrecipMM]
{\data};
\addlegendentry{Rainfall depth}
\addplot+[const plot mark left, fill=none,dashed] table[x=Time,y=SumP]
{\data};
\addlegendentry{Mass Rainfall}
\nextgroupplot[ymax=100,height=4cm]
\addplot+[const plot mark left,fill=none] table[x=Time,y=HourlyPrecipMM]
{\data};
\addlegendentry{Rainfall depth}
\end{groupplot}
\end{tikzpicture}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-engine: xetex
%%% TeX-master: t
%%% End: