我正在尝试绘制一个被灯光照亮的房间,所以我走到这一步,但我不知道颜色图有什么选择
\documentclass[border=0.2cm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}
\pgfplotsset{compat = newest}
\begin{document}
\begin{tikzpicture}[scale=0.25]
\begin{axis}[
axis equal image,
grid = both,
minor tick num = 2,
xlabel = {$x$},
ylabel = {$y$},
zlabel = {$z$},
major grid style = {draw = lightgray},
minor grid style = {draw = lightgray!25},
legend cell align={left},
ymin = -1, ymax = 1,
xmin = -1, xmax = 1,
scale = 3,
zmin = 0, zmax = 1.1,
z buffer = sort,
]
% top of the cone
\addplot3[
surf,
shader = interp,
samples = 50,
samples y = 5,
domain = 0:2*pi,
domain y = 0:1,
opacity = 0.65,
colormap/yellowwhite,
]
(
{(cos(deg(x)))*(1-y)},
{(sin(deg(x)))*(1-y)},
{y}
);
\end{axis}
\end{tikzpicture}
\end{document}
答案1
这一切都解释在手册:
第四章:参考资料
→标记、线条样式、(背景)颜色和色彩图
→色彩地图
这是手册第 195 页,标签为“修订版 1.18.1 (2021/05/15)”。例如,您可以定义一个颜色图并为其命名:
\pgfplotsset{
colormap={my colormap}{rgb=(0,0,1) color=(black) rgb255=(238,140,238)},
}
然后将其与 一起使用colormap name=my colormap
。
\documentclass[border=0.2cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.18,
colormap={my colormap}{rgb=(0,0,1) color=(black) rgb255=(238,140,238)},
}
\begin{document}
\begin{tikzpicture}[scale=0.25]
\begin{axis}[
axis equal image,
grid = both,
minor tick num = 2,
xlabel = {$x$},
ylabel = {$y$},
zlabel = {$z$},
major grid style = {draw = lightgray},
minor grid style = {draw = lightgray!25},
legend cell align={left},
ymin = -1, ymax = 1,
xmin = -1, xmax = 1,
scale = 3,
zmin = 0, zmax = 1.1,
z buffer = sort,
]
\addplot3[
surf,
shader = interp,
samples = 50,
samples y = 5,
domain = 0:2*pi,
domain y = 0:1,
opacity = 0.65,
colormap name=my colormap,
]
(
{(cos(deg(x)))*(1-y)},
{(sin(deg(x)))*(1-y)},
{y}
);
\end{axis}
\end{tikzpicture}
\end{document}
你想要的可能看起来像这样:
\pgfplotsset{
colormap={yellowwhite}{rgb=(1,1,0) rgb=(1,1,0.8) rgb=(1,1,1)},
}
...
\addplot3[..., colormap name=yellowwhite] (...); ...
预定义的颜色图,\usepgfplotslibrary{colormaps}
当不是已使用,是viridis
和hot
(默认)。如果加载库,则还有pgfplots
colormaps
更多颜色图可供使用:autumn
,,,,,,,,,等:请参阅bled
bright
bone
cold
copper
copper2
earth
手册在下面相关库→色彩图(我的版本第 430 页)。
带有颜色图的示例hsv2
。请注意\pgfplotsset{colormap/hsv2}
加载它的顺序;然后它可以与一起使用colormap name=hsv2
(当然,您可以在可选参数colormap/hsv2
中使用而根本\addplot3
不执行此操作\pgfplotsset{colormap/hsv2}
,但如果您在同一文档中多次使用此颜色图,效率会较低)。
\documentclass[border=0.2cm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}
\pgfplotsset{compat=1.18}
\pgfplotsset{colormap/hsv2} % <-------- this loads the 'hsv2' color map
\begin{document}
\begin{tikzpicture}[scale=0.25]
\begin{axis}[
axis equal image,
grid = both,
minor tick num = 2,
xlabel = {$x$},
ylabel = {$y$},
zlabel = {$z$},
major grid style = {draw = lightgray},
minor grid style = {draw = lightgray!25},
legend cell align={left},
ymin = -1, ymax = 1,
xmin = -1, xmax = 1,
scale = 3,
zmin = 0, zmax = 1.1,
z buffer = sort,
]
\addplot3[
surf,
shader = interp,
samples = 50,
samples y = 5,
domain = 0:2*pi,
domain y = 0:1,
opacity = 0.65,
% or 'colormap/hsv2', but this is less efficient
colormap name=hsv2,
]
(
{(cos(deg(x)))*(1-y)},
{(sin(deg(x)))*(1-y)},
{y}
);
\end{axis}
\end{tikzpicture}
\end{document}