I am wondering if there is the possibility in pgfplots to define a color according to the value of the data, which should be plotted?
What I am thinking of is to define individual colors for all values < 0 and values > 0 and white for values = 0 and then combine these colors in a colormap.
Hopefully, one can understand what I am talking about. I can also think of a MWE, but right now I just whant to know if it is actually possible and if yes, how to proceed.
Edit
To clarify my problem, I had a look at related questions and found this example and may add a MWE:
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}
\pgfplotsset{compat=newest}
\pgfplotsset{
colormap/corr2Dplus/.style={colormap={corr2Dplus}{
rgb255=(255,255,255);
rgb255=(255,255,0);
rgb255=(255,0,0);
rgb255=(102,0,0);
}
},
colormap/corr2Dminus/.style={colormap={corr2Dminus}{
rgb255=(255,255,255);
rgb255=(0,255,255);
rgb255=(0,0,255);
rgb255=(0,0,102);
}
},
}
\begin{filecontents}[overwrite]{data.txt}
x y z
0 0 0
0 1 0
1 0 1
1 1 1
2 0 2
2 1 2
3 0 3
3 1 3
4 0 -3
4 1 -3
5 0 -2
5 1 -2
6 0 -1
6 1 -1
7 0 0
7 1 0
\end{filecontents}
\begin{document}
\def\zlim{3}% <- later, I calculate this value automatically
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
colormap/corr2Dplus,
colorbar,
title=positive values,
]
\addplot3[
mesh/rows=8,
surf,
colormap/corr2Dplus,
shader=interp,
]
table[
z expr={\thisrow{z} > 0},
] from {data.txt};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
colormap/corr2Dminus,
colorbar,
title=negative values,
]
\addplot3[
mesh/rows=8,
surf,
colormap/corr2Dminus,
shader=interp,
]
table[
z expr={\thisrow{z} < 0}
] from {data.txt};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
colormap/corr2Dminus,
colorbar,
title=negative values,
]
\addplot3[
mesh/rows=8,
surf,
colormap/corr2Dminus,
shader=interp,
]
table[
z expr={\thisrow{z} < 0}
] from {data.txt};
\end{axis}
\end{tikzpicture}
\end{document}
Now, my question is: How can I combine the two pictures into one?


colormaprespectively. Thus, maybe you first have a look at the corresponding section in the PGFPlots manual to see howcolormaps can be defined and how colors can be accessed. – Stefan Pinnow Feb 25 '21 at 16:45