我想将平面下方所有 z 值为负的点涂成红色,将 z 值为正的点涂成青色!80。我搜索了一个小时,但不知道该怎么做。有什么建议吗?
\documentclass[12pt]{standalone}
\usepackage[cmyk]{xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{tikz}
\begin{document}
\def\pu{3}
\def\po{20}
\def\ku{2}
\def\ko{10}
\def\K{2000000}
\def\MP{500000}
\def\eo{\po-\ku}
\def\eu{\pu-\ko}
\def\layerwidth{}
\begin{tikzpicture}
\begin{axis}[
view={20}{20},
grid=major,
z buffer=sort,
xmin=0,xmax=1,
ymin=\eu,ymax=\eo,
enlargelimits=upper,
xtick={0,0.5,1},
ytick={},
xlabel={x},
ylabel={y},
zlabel={z},
colormap={summap}{
color=(red); color=(white); color=(cyan!80)
},
scatter/use mapped color={
draw=mapped color,fill=mapped color},
]
\addplot3
[surf,
domain=0:1,y domain=\eu:\eo]
{(x*\MP)*y-\K};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以设置point meta min=-1, point meta max=1
(或其他一些关于 0` 对称的小范围):
\documentclass[12pt]{standalone}
\usepackage[cmyk]{xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{tikz}
\begin{document}
\def\pu{3}
\def\po{20}
\def\ku{2}
\def\ko{10}
\def\K{2000000}
\def\MP{500000}
\def\eo{\po-\ku}
\def\eu{\pu-\ko}
\def\layerwidth{}
\begin{tikzpicture}
\begin{axis}[
view={20}{20},
grid=major,
z buffer=sort,
xmin=0,xmax=1,
ymin=\eu,ymax=\eo,
enlargelimits=upper,
xtick={0,0.5,1},
ytick={},
xlabel={x},
ylabel={y},
zlabel={z},
colormap={summap}{
color=(red); color=(white); color=(cyan!80)
}
]
\addplot3
[surf,
domain=0:1,y domain=\eu:\eo, point meta min=-1, point meta max=1]
{(x*\MP)*y-\K};
\end{axis}
\end{tikzpicture}
\end{document}