希望我能在内容中比在标题中更清楚地描述我的问题。它可能更多地与可视化策略有关,而不是特定的 pgfplots 技术。问题是关于二维输入的回归,但请让我从一维输入开始。
假设在我的实验中,我改变输入 x,并观察输出 y。我重复实验三次。该图显示了结果(代码列在最后):
现在假设我的实验有两个输入 x 和 y,以及一个输出 z。对于一个实验的观察结果,可以绘制如下:
然而,对于重复实验(比如 4-5 次),包含所有这些结果的 3-D 图相当混乱。平均值和偏差图看起来更好,但肯定丢失了信息。以下是当实验重复两次(两组观察结果)时的示例,图将是:
是否有任何策略可以更好地可视化这种情况(多个 xyz)?“更好”可能意味着每个单独的实验都清晰地呈现,并且多个实验一起呈现以便于比较。
仅供参考,这些是生成图表的 pgfplots 代码。
多重 xyz 图:
\begin{tikzpicture}[scale=0.8]
\begin{axis}
[scale only axis, width=0.35\textwidth,
xlabel=x, ylabel=y, zlabel=z, title=Two dimensional input,]
\addplot3[surf,mesh/rows=5] coordinates {
(0,0,0) (1,0,0) (2,0,0) (3,0,0)
(0,1,0.1) (1,1,0.3) (2,1,0.3) (3,1,0.4)
(0,2,0.15) (1,2,0.5) (2,2,0.5) (3,2,0.5)
(0,3,0.65) (1,3,0.60) (2,3,0.65) (3,3,0.45)
(0,4,0.8) (1,4,0.75) (2,4,0.85) (3,4,0.65)
};
\addplot3[surf,mesh/rows=5] coordinates {
(0,0,0.1) (1,0,0.1) (2,0,0) (3,0,0)
(0,1,0.3) (1,1,0.2) (2,1,0.2) (3,1,0.4)
(0,2,0.15) (1,2,0.6) (2,2,0.5) (3,2,0.5)
(0,3,0.55) (1,3,0.7) (2,3,0.65) (3,3,0.45)
(0,4,0.6) (1,4,0.85) (2,4,0.65) (3,4,0.35)
};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[scale only axis, width=0.3\textwidth,
xlabel=x, ylabel=y, zlabel=z, title=Mean and Deviation,]
\addplot3[surf,mesh/rows=5,
error bars/z dir=both, error bars/z fixed=0.1,] coordinates {
(0,0,0.05) (1,0,0.05) (2,0,0) (3,0,0)
(0,1,0.2) (1,1,0.25) (2,1,0.25) (3,1,0.4)
(0,2,0.15) (1,2,0.55) (2,2,0.5) (3,2,0.5)
(0,3,0.65) (1,3,0.65) (2,3,0.65) (3,3,0.45)
(0,4,0.7) (1,4,0.80) (2,4,0.75) (3,4,0.5)
};
\end{axis}
\end{tikzpicture}
单个 xyz 图:
\begin{tikzpicture}[scale=0.8]
\begin{axis}
[scale only axis, width=0.35\textwidth,
xlabel=x, ylabel=y, zlabel=z, title=Two dimensional input,]
\addplot3[surf,mesh/rows=5] coordinates {
(0,0,0) (1,0,0) (2,0,0) (3,0,0)
(0,1,0.1) (1,1,0.3) (2,1,0.3) (3,1,0.4)
(0,2,0.15) (1,2,0.5) (2,2,0.5) (3,2,0.5)
(0,3,0.65) (1,3,0.60) (2,3,0.65) (3,3,0.45)
(0,4,0.8) (1,4,0.75) (2,4,0.85) (3,4,0.65)
};
\end{axis}
\end{tikzpicture}
\hfill
\begin{tikzpicture}[scale=0.8]
\begin{axis}[view={0}{90}, scale only axis, width=0.3\textwidth,
xlabel=x, ylabel=y, zlabel=z, title=Top view of two dimensional input, ]
\addplot3[surf,mesh/rows=5] coordinates {
(0,0,0) (1,0,0) (2,0,0) (3,0,0)
(0,1,0.1) (1,1,0.3) (2,1,0.3) (3,1,0.4)
(0,2,0.15) (1,2,0.5) (2,2,0.5) (3,2,0.5)
(0,3,0.65) (1,3,0.60) (2,3,0.65) (3,3,0.45)
(0,4,0.8) (1,4,0.75) (2,4,0.85) (3,4,0.65)
};
\end{axis}
\end{tikzpicture}
多重 xy 图:
\begin{tikzpicture}
\begin{axis}
[scale only axis, width=0.3\textwidth,
xlabel=x, ylabel=y, title=One dimensional input]
\addplot coordinates{(0, 0.6) (0.1, 0.25) (0.2, 0.1) (0.3, 0.06) (0.4, 0.02) (0.5, 0.01)};
\addplot coordinates{(0, 0.7) (0.1, 0.1) (0.2, 0.125) (0.3, 0.08) (0.4, 0.016) (0.5, 0.02)};
\addplot coordinates{(0, 0.5) (0.1, 0.15) (0.2, 0.15) (0.3, 0.10) (0.4, 0.012) (0.5, 0.03)};
\legend{exp1, exp2, exp3}
\end{axis}
\end{tikzpicture}
\hfill
\begin{tikzpicture}
\begin{axis}
[scale only axis, width=0.3\textwidth,
xlabel=x, ylabel=y, title=Mean and Deviation]
\addplot[ error bars/.cd, y dir=both, y explicit, ]
coordinates{(0, 0.6) +- (0, 0.1)
(0.1, 0.1) +- (0, 0.1)
(0.2, 0.125) +- (0, 0.025)
(0.3, 0.08) +- (0, 0.08)
(0.4, 0.016) +- (0, 0.04)
(0.5, 0.02) +- (0, 0.02)};
\end{axis}
\end{tikzpicture}
然而,
答案1
要获得这张图片...
...尝试这些命令,
pdflatex example.tex; asy -twosided *.asy; pdflatex example.tex
...编译这个例子。
\documentclass[]{article}
\usepackage[]{asymptote}
\begin{document}
Two Dimensional Input
\vspace{3cm}
\begin{asy}
settings.render=4;
import three;
import graph3;
currentlight=White;
currentprojection=orthographic(3,-5,1,center=true);
size(5cm);
size3(5cm,5cm,5cm, IgnoreAspect);
render render=render(compression=Low,merge=true);
triple[][] t1 =
{
{(0,0,0), (1,0,0), (2,0,0), (3,0,0) },
{(0,1,0.1), (1,1,0.3), (2,1,0.3), (3,1,0.4)},
{(0,2,0.15), (1,2,0.5), (2,2,0.5), (3,2,0.5)},
{(0,3,0.65), (1,3,0.60), (2,3,0.65), (3,3,0.45)},
{(0,4,0.8), (1,4,0.75), (2,4,0.85), (3,4,0.65)}
};
triple[][] t2 =
{
{(0,0,0.1), (1,0,0.1), (2,0,0), (3,0,0)},
{(0,1,0.3), (1,1,0.2), (2,1,0.2), (3,1,0.4)},
{(0,2,0.15), (1,2,0.6), (2,2,0.5), (3,2,0.5)},
{(0,3,0.55), (1,3,0.7), (2,3,0.65), (3,3,0.45)},
{(0,4,0.6),(1,4,0.85),(2,4,0.65),(3,4,0.35)}
};
draw(surface(t1), blue+opacity(0.9));
draw(surface(t2), red+opacity(0.6));
xaxis3("$x$",Bounds,InTicks);
yaxis3("$y$",Bounds,InTicks);
zaxis3("$z$",Bounds,InTicks);
\end{asy}
\end{document}
显然,您需要在系统中安装 pdflatex、asymptote 包和 asymptote。如果运气好的话,如果您使用最新版本的 Acrobat Reader 打开 PDF,您还会在 PDF 中获得交互式 3D 对象。
不用说,我同意杰克的观点,即使你可以用 pgfplots 来做到这一点(你不能简单地做到这一点),但它仍然非常令人困惑。
答案2
另一个类似的解决方案,但使用纯粹的pgfplots
(不是asymptote
),是将opacity=0.5
选项添加到表面。如下所示:
\addplot3[surf,mesh/rows=5, opacity=0.5] coordinates { ...
虽然它仍然不完美,但至少图像是物理的(幽灵表面相互渗透),并且不会因创建不可能的 3D 对象而伤害大脑。请注意,该技巧仅适用于值 0.5(即,一个表面覆盖另一个表面更多),否则表面会开始以大脑认为奇怪的方式重叠。
您甚至可以对误差线(使用)使用相同的技巧opacity
来获得以下效果:
以下是最后一张图的完整代码:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.8]
\begin{axis}
[scale only axis, width=0.35\textwidth,
xlabel=x, ylabel=y, zlabel=z, title=Two dimensional input,]
\addplot3[surf,mesh/rows=5,opacity=0.5] coordinates {
(0,0,0) (1,0,0) (2,0,0) (3,0,0)
(0,1,0.1) (1,1,0.3) (2,1,0.3) (3,1,0.4)
(0,2,0.15) (1,2,0.5) (2,2,0.5) (3,2,0.5)
(0,3,0.65) (1,3,0.60) (2,3,0.65) (3,3,0.45)
(0,4,0.8) (1,4,0.75) (2,4,0.85) (3,4,0.65)
};
\addplot3[surf,mesh/rows=5, opacity=0.5] coordinates {
(0,0,0.1) (1,0,0.1) (2,0,0) (3,0,0)
(0,1,0.3) (1,1,0.2) (2,1,0.2) (3,1,0.4)
(0,2,0.15) (1,2,0.6) (2,2,0.5) (3,2,0.5)
(0,3,0.55) (1,3,0.7) (2,3,0.65) (3,3,0.45)
(0,4,0.6) (1,4,0.85) (2,4,0.65) (3,4,0.35)
};
\addplot3[mesh/rows=5,
error bars/z dir=both, error bars/z fixed=0.1, opacity=0.3, draw=none] coordinates {
(0,0,0.05) (1,0,0.05) (2,0,0) (3,0,0)
(0,1,0.2) (1,1,0.25) (2,1,0.25) (3,1,0.4)
(0,2,0.15) (1,2,0.55) (2,2,0.5) (3,2,0.5)
(0,3,0.65) (1,3,0.65) (2,3,0.65) (3,3,0.45)
(0,4,0.7) (1,4,0.80) (2,4,0.75) (3,4,0.5)
};
\end{axis}
\end{tikzpicture}
\end{document}