I want to create a plot where positive and negative values have a different color. MWE:
\documentclass[tikz]{standalone}
\usepackage{filecontents}
\usepackage{xstring}
\begin{filecontents}{data.txt}
-3.5 nan
-3.375 nan
-3.25 nan
-3.125 0.000121769833828
-3.0 0.000901599938148
-2.875 0.0014834598325
-2.625 0.00588102803508
-2.25 0.0720113632674
-2.125 0.0314393757219
-1.875 0.0306933267171
-1.75 0.07029144932
-1.375 -0.0342012822215
-1.125 -0.0171975784671
-0.75 -0.0405296273749
-0.625 -0.0330713662613
-0.375 -0.00156002201142
0.0 0.044002036309
0.125 0.0634327667271
0.375 0.0153149732892
0.75 -0.00313272843988
0.875 0.0229547104663
1.125 0.0219197613133
1.625 0.0112441717079
1.875 -0.000229179659447
2.0 nan
2.625 nan
\end{filecontents}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{onlyPositive/.style={y filter/.code={
\pgfmathparse{##1<0 ? nan : ##1}}, unbounded coords=jump}}
\pgfplotsset{onlyNegative/.style={y filter/.code={
\pgfmathparse{##1>=0 ? nan : ##1}}, unbounded coords=jump}}
\begin{axis}[grid]
\addplot [] file {data.txt};
\addplot [onlyPositive,blue,xshift=2mm,very thick] file {data.txt};
\addplot [onlyNegative,red,xshift=2mm,very thick] file {data.txt};
\end{axis}
\end{tikzpicture}
\end{document}
Now, I want for example the graphs positive part be blue, negative be red. I tried math. expressions to add 2 plots, one for neg, one for pos. But then, there are holes in the graph between sign change, since I have two plots now (as you can see in the figure). What I really want is that the color automatically changes on the lines.
Thank you for helping me out! Max
