有什么办法可以切换此图表的颜色吗?目前,较低的值为蓝色,较高的值为红色。有没有简单的方法可以做到这一点?
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={60}{30}]
\addplot3 [
mesh,
z buffer=sort,
samples=20,
domain=-1:0,
y domain=0:2*pi,
] (
{sqrt(1-x^2) * cos(deg(y))},
{sqrt( 1-x^2 ) * sin(deg(y))},
x
);
\end{axis}
\end{tikzpicture}
\end{document}
答案1
基于这个答案. 该色彩图称为hot
。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15} % ADDED
\usepgfplotslibrary{colormaps} % ADDED
\begin{document}
\begin{tikzpicture}
\pgfplotsset{colormap/hot} % ADDED
\begin{axis}[view={60}{30},colormap={reverse hot}{indices of colormap={\pgfplotscolormaplastindexof{hot},...,0 of hot}}] % ADDED
\addplot3 [
mesh,
z buffer=sort,
samples=20,
domain=-1:0,
y domain=0:2*pi,
] (
{sqrt(1-x^2) * cos(deg(y))},
{sqrt( 1-x^2 ) * sin(deg(y))},
x
);
\end{axis}
\end{tikzpicture}
\end{document}
答案2
point meta
Myles 的回答已经非常优雅和简短了,但可以说,从默认值反转z
为甚至更短-z
。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={60}{30}]
\addplot3 [
mesh,
z buffer=sort,
samples=20,
domain=-1:0,
y domain=0:2*pi,point meta=-z
] (
{sqrt(1-x^2) * cos(deg(y))},
{sqrt( 1-x^2 ) * sin(deg(y))},
x
);
\end{axis}
\end{tikzpicture}
\end{document}