从例子开始http://pgfplots.net/tikz/examples/轮廓和表面/,我想对由表格定义的表面进行投影。X 和 Y 投影工作正常,但 Z 投影出现在顶部,而不是底部。我猜是因为对数刻度。我做错了什么?下图说明了我的问题。(我知道,这张图片不吸引人,也不合理,但我想缩小 MWE 的尺寸)
版本:我还附上了一张由我的完整数据集生成的图像。Y 投影与我预期的差不多。X 投影很有趣:只有垂直线,没有连接。看起来投影很糟糕:投影到 Y 轴的虚线被投影到 X 平面,没有任何连接。我期望的是像 Y 投影中的虚线。我不知道 Z 投影是什么。看起来它在最高值周围形成了一些凹凸,仅此而已。
我与示例有两点不同:一是对数刻度,二是表格数据。我将 Z 刻度改为线性并设置zmin=1e-4, zmax=.1
。结果是第三张图。基于此,我猜测 Y 投影没问题,X 投影使用了错误的投影方向,而 Z 投影无法处理这种大范围数据。
\documentclass[border=10pt]{standalone}
\usepackage{verbatim}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
%http://pgfplots.net/tikz/examples/contour-and-surface/
\pgfplotstableset{%
col sep=semicolon,
x index=0,
y index=1,
z index=2,
header=false
}%
\begin{filecontents*}{data/XYZ.csv}
2016; 1; 32.7e-9
2016;10; 1560e-9
2016;20; 9811e-9
2016;25; 5204e-9
2015; 1; 199e-9
2015;10; 438e-9
2015;20; 674e-9
2015;25; 1718e-9
2014; 1; 199e-9
2014;10; 2446e-9
2014;20; 1893e-9
2014;25; 2670e-9
1994; 1; 76957E-9
1994;10;54545455e-9
1994;20; 1390462e-9
1994;25; 1440795e-9
1993; 1; 1167453e-9
1993;10; 7484185e-9
1993;20; 7484185e-9
1993;25; 8876163e-9
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{
every axis/.append style={
scale only axis,
width=\textwidth,
height=\textwidth,
xtick={1995,2000,2005,2010,2015},
ytick={1,10,20,25},
ztick={1e-8,1e-6,1e-4,1e-2,1e-0}
},
/tikz/every picture/.append style={
trim axis left,
trim axis right,
}
}
\begin{axis}
[ %nodes near coords={(\coordindex)},
domain=1980:2020,
domain y=1:40,
footnotesize,
title={Hillside},
/pgf/number format/.cd,
use comma,
1000 sep={},
xlabel=Year,
ylabel=position,
xmin=1980, xmax=2020,% x scale
ymin=1, ymax=40, % y scale
zmin=1e-12, zmax=1, % z scale
xlabel=Year,
zmode = log,
grid=major,
grid style={dotted},
colormap/jet,
zmode=log,
]
\addplot3
[surf]
table {data/XYZ.csv};
% This is the Z (bottom) projection
\addplot3[
contour gnuplot={
% cdata should not be affected by z filter:
output point meta=rawz,
number=15,
labels=false,
},
z filter/.code=\def\pgfmathresult{1E-4},
]
table {data/XYZ.csv};
% This is the X projection
\addplot3[
domain=1980:2020,
domain y=1:30,
% we want 1d (!) individually colored mesh segments:
mesh, patch type=line,
x filter/.code=\def\pgfmathresult{1980},
]
table {data/XYZ.csv};
%% This is the Y projection
\addplot3[
% we want 1d (!) individually colored mesh segments:
mesh, patch type=line,
y filter/.code=\def\pgfmathresult{40},
]
table {data/XYZ.csv};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您的 z 轴是对数缩放的,即您设置的值z filter
是指数。由于您希望将轮廓置于 10 −4处,因此您必须设置z filter/.code={\def\pgfmathresult{-4}}
。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
%http://pgfplots.net/tikz/examples/contour-and-surface/
\pgfplotstableset{%
col sep=semicolon,
x index=0,
y index=1,
z index=2,
header=false
}%
\begin{filecontents*}{data/XYZ.csv}
2016; 1; 32.7e-9
2016;10; 1560e-9
2016;20; 9811e-9
2016;25; 5204e-9
2015; 1; 199e-9
2015;10; 438e-9
2015;20; 674e-9
2015;25; 1718e-9
2014; 1; 199e-9
2014;10; 2446e-9
2014;20; 1893e-9
2014;25; 2670e-9
1994; 1; 76957E-9
1994;10;54545455e-9
1994;20; 1390462e-9
1994;25; 1440795e-9
1993; 1; 1167453e-9
1993;10; 7484185e-9
1993;20; 7484185e-9
1993;25; 8876163e-9
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{
every axis/.append style={
scale only axis,
width=\textwidth,
height=\textwidth,
xtick={1995,2000,2005,2010,2015},
ytick={1,10,20,25},
ztick={1e-8,1e-6,1e-4,1e-2,1e-0}
},
/tikz/every picture/.append style={
trim axis left,
trim axis right,
}
}
\begin{axis}
[ %nodes near coords={(\coordindex)},
domain=1980:2020,
domain y=1:40,
footnotesize,
title={Hillside},
/pgf/number format/.cd,
use comma,
1000 sep={},
xlabel=Year,
ylabel=position,
xmin=1980, xmax=2020,% x scale
ymin=1, ymax=40, % y scale
zmin=1e-12, zmax=1, % z scale
xlabel=Year,
zmode = log,
grid=major,
grid style={dotted},
colormap/jet,
zmode=log,
]
\addplot3
[surf]
table {data/XYZ.csv};
% This is the Z (bottom) projection
\addplot3[
contour gnuplot={
% cdata should not be affected by z filter:
output point meta=rawz,
number=15,
labels=false,
},
z filter/.code={\def\pgfmathresult{-4}},
]
table {data/XYZ.csv};
% This is the X projection
\addplot3[
domain=1980:2020,
domain y=1:30,
% we want 1d (!) individually colored mesh segments:
mesh, patch type=line,
x filter/.code={\def\pgfmathresult{1980}},
]
table {data/XYZ.csv};
%% This is the Y projection
\addplot3[
% we want 1d (!) individually colored mesh segments:
mesh, patch type=line,
y filter/.code={\def\pgfmathresult{40}},
]
table {data/XYZ.csv};
\end{axis}
\end{tikzpicture}
\end{document}