I'm trying to automatically generate a plot, which visualizes the difference of two other plots. The input source is a single(!) file. The data is filtered by one column with /tr/rowfilter
. Here is an example image:
I want that the "difference (b-a)" plot is generated by TikZ/PGFPlots/PGFPlotstable/LaTeX. I've experimented with /pgfplots/x filter
, but I wasn't successful (I don't even know, if it's possible)
Here is the corresponding tex example:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfkeys{
/tr/rowfilter/.style 2 args={
/pgfplots/x filter/.append code={
\edef\arga{\thisrow{#1}}
\edef\argb{#2}
\ifx\arga\argb
\else
\def\pgfmathresult{}
\fi
}
}
}
\usepackage{filecontents}
\begin{filecontents}{diagram.dat}
x y kind
1 1 a
2 6 a
3 10 a
4 13 a
5 15 a
1 1 b
2 7 b
3 13 b
4 17 b
5 20 b
\end{filecontents}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{\huge The way it is now:}
\vspace{0.5cm}
\begin{tikzpicture}
\begin{axis}[
filter discard warning=false,
height=8cm,
width=12cm,
grid=major,
legend pos=outer north east
]
\addplot table[/tr/rowfilter={kind}{a}] {diagram.dat};
\addlegendentry{curve a}
\addplot table[/tr/rowfilter={kind}{b}] {diagram.dat};
\addlegendentry{curve b}
\end{axis}
\end{tikzpicture}
\vspace{1cm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{\huge The way it should look like}
\vspace{0.5cm}
\begin{tikzpicture}
\begin{axis}[
filter discard warning=false,
height=8cm,
width=12cm,
grid=major,
legend pos=outer north east
]
\addplot table[/tr/rowfilter={kind}{a}] {diagram.dat};
\addlegendentry{curve a}
\addplot table[/tr/rowfilter={kind}{b}] {diagram.dat};
\addlegendentry{curve b}
%%% This should be generated with Tikz/PGFPLOTS/PGFPLOTSTABLE/Latex!!!
\addplot coordinates {
(1,0)
(2,1)
(3,3)
(4,4)
(5,5)
};
\addlegendentry{difference (b-a)}
\end{axis}
\end{tikzpicture}
\end{document}
Can you help me?