# Strategies to visualize multiple two-dimensional regressions?

Hopefully I can describe my question more clear here in the content than in the title. It might be more about visualization strategy than specific pgfplots techniques. The problem is about regressions of two-dimensional input, but please let me start with one-dimensional input.

Say in my experiment I vary the input x, and observe the output y. I repeat the experiments three times. The plot shows the results (code are listed at end):

Now assume my experiment have two inputs x and y, and an output z. For the observations from one experiment, it can be plotted like this:

However, for repeated experiments (say 4-5 times), the 3-D plot containing all these results is rather confusing. The mean and deviation plot looks better but certainly lost information. Here is an example when the experiments are repeated twice (two set of observations), the plots will be:

Is there any strategy that can visualize this case (multiple x-y-z) better? "Better" maybe in the sense that each individual experiment is presented clearly, and also multiple experiments are presented together for easy comparison.

Just for reference, these are the pgfplots code generating the plots.

Muliple x-y-z plot:

\begin{tikzpicture}[scale=0.8]
\begin{axis}
[scale only axis, width=0.35\textwidth,
xlabel=x, ylabel=y, zlabel=z, title=Two dimensional input,]
(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)
};
(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,]
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}


Single x-y-z plot:

\begin{tikzpicture}[scale=0.8]
\begin{axis}
[scale only axis, width=0.35\textwidth,
xlabel=x, ylabel=y, zlabel=z, title=Two dimensional input,]
(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, ]
(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}


Multiple x-y plot:

\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}


However,

-
pgfplots doesn't support face intersections of 3D plots (it is in the stated in manual). You can try with Asymptote (asymptote.sourceforge.net) and the asymptote package (ctan.org/pkg/asymptote) instead. – alfC Aug 21 '12 at 5:30
I don't think plotting several 3D surfaces in the same plot is a good idea. It would be very hard to get any useful information out of that. I would probably go with just a mesh plot (not surf) of the mean surface together with the error bars (similar to your "Mean and Deviation" example). Alternatively, you might want to think about using several small heatmaps instead of 3D surfaces. It really depends on what exactly you're trying to show, though. Could you provide some more information on what kind of data you want to show? – Jake Aug 21 '12 at 12:55
@Jake, I have two parameters x and y, I would like to plot the joint effect of x and y on some output variable z. e.g. x=1:0.5:10, y=1:0.25:10. The joint effect on z may vary a little bit (e.g. noise, but may also be trend) over multiple discrete time points (i.e. multiple experiments). I am trying to show the output z, the noise (standard dev.), and trend (if there is any). I haven't produce the real output yet, which takes time to finish. – Causality Aug 21 '12 at 23:18
@alfC, although I have not been able to make use of it, the concept of surface intersection is interesting. Thanks. – Causality Aug 21 '12 at 23:24

To obtain this picture...

...try these commands,

pdflatex example.tex; asy  -twosided *.asy; pdflatex example.tex


...to compile this example.

\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}


Obviously you need to have pdflatex, asymptote package and asymptote installed in your system. With a bit of luck you also get an interactive 3D object in your PDF if you open in it with a recent version of Acrobat Reader.

Needless to day I agree with Jake that even if you could do this with pgfplots (which you can not simply) it is very confusing.

-
the face interaction and interactive 3D object in the PDF is cool. Although not perfect, it does provide a new dimension for visualizing the type of problem. Meanwhile, the syntax of asymptote seems more like standard programming language than tex, which is very interesting. Would like to know more on the asymptote. – Causality Aug 28 '12 at 21:10

Another similar solution but using purely pgfplots (not asymptote), is to add the opacity=0.5 option to the surfaces. As this:

 \addplot3[surf,mesh/rows=5, opacity=0.5] coordinates { ...


It is still not perfect but at least the image is physical (the ghost surfaces interpenetrate) and doesn't hurt the brain by creating an impossible 3D object. Note that the trick only works for the value 0.5 (i.e. not surface covers the other more), otherwise the surfaces start overlapping in a way that the brain finds weird.

You can even play the same trick with the error bars (with opacity) to obtain the following effect:

What follows is the full code for the last figure:

\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,]
(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)
};
(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)
};