我想知道是否可以pgfplots
根据应该绘制的数据值定义颜色?
我的想法是为所有定义单独的颜色values < 0
和values > 0
白色,values = 0
然后将这些颜色组合在一起colormap
。
希望大家能理解我在说什么。我也能想到 MWE,但现在我只想知道它是否真的可行,如果可行,该如何进行。
编辑
为了澄清我的问题,我查看了相关问题并发现这个例子并可能添加 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}
现在,我的问题是:我怎样才能将两张图片合并为一张?
答案1
简单地组合colormap
s 似乎有效......
% used PGFPlots v1.17
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
colormap={corr2D}{
rgb255=(0,0,102);
rgb255=(0,0,255);
rgb255=(0,255,255);
rgb255=(255,255,255);
rgb255=(255,255,0);
rgb255=(255,0,0);
rgb255=(102,0,0);
},
}
\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}
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
colormap name=corr2D,
colorbar,
]
\addplot3[
mesh/rows=8,
surf,
shader=interp,
] table {data.txt};
\end{axis}
\end{tikzpicture}
\end{document}