# Plotting two 2D-plots in a 3D plot using pgfplots

I am trying to create a 3D plot similar to a standard xyz coordinate system by using pgfplots. I want to plot two 2D plots one in x1-y and one in x2-z plane, similar to the following illustration (some of my x-labels are graphics similar to this post, and I hope this does not limit me in what I am looking for).

How can I modify my code below to achieve this?

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}

\begin{filecontents*}{data.csv}
a,b,c
1,4,1
2,3,2
3,5,3
4,1,4
5,3,5
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[
xlabel={$x_1$},
xtick={1, 2, 3, 4, 5},
xticklabels={\includegraphics[scale=0.05]{example-image-a},\includegraphics[scale=0.05]{example-image-b}, 3, 4, 5},
]
\addplot+ table [x=a, y=b, col sep=comma] {data.csv};
\end{axis}

\begin{axis}[xlabel={$x_2$}]
\addplot+ table [x=a, y=c, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}


Use \addplot3 to make a 3D-plot, and then set the either x or y to zero (depending on which plane you're in) with x expr=0/y expr=0 as in the code below.

I also set axis lines=center and modified the view, to get something similar to your sketch.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usetikzlibrary{backgrounds}
\begin{filecontents*}{data.csv}
a,b,c
1,4,1
2,3,2
3,5,3
4,1,4
5,3,5
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[
axis lines=center,view={115}{45},
xlabel={$x_1$}, ylabel=$x_2$,zlabel=$z$,
xtick={1, 2, 3, 4, 5},
xticklabels={\includegraphics[scale=0.05]{example-image-a},\includegraphics[scale=0.05]{example-image-b}, 3, 4, 5},
]
\addplot3+ table [y=a, z=b, x expr=0,col sep=comma] {data.csv};

\addplot3+ table [x=a, z=c, y expr=0, col sep=comma] {data.csv};

\begin{scope}[on background layer]
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}


• Fantastic! Is it also possible to control the angle between the axes, e.g., to make it wider or narrower, or also changing the orientation of the 3D plot? – AFP Jun 14 '16 at 18:45
• @Ahmad Try playing with the view parameters, e.g. view={135}{15}. The first number defines rotation around the z-axis, the second is the angle above the xy-plane. What do you mean by 'orientation of the plot'? – Torbjørn T. Jun 14 '16 at 18:51
• @Ahmad I could be wrong, but I don't think that can be done with the above configuration, because the axes are orthogonal to each other. – Torbjørn T. Jun 14 '16 at 19:19
• @KKK To be brutally honest, this question isn't about plotting smooth curves, it's about the configuration of the axes, and in that sense your answer doesn't contribute anything new. So I for one won't be upvoting, sorry. – Torbjørn T. Jun 14 '16 at 19:24
• @Ahmad Please try to include all your requirements in the question at once. Having to revisit accepted answers with new additions (that are somewhat unrelated to the original one) is actually a bit annoying. But see the updated answer. If you want a solution that doesn't require manually adding the numbers, ask a new question. – Torbjørn T. Jun 14 '16 at 20:10
\documentclass{standalone}
\usepackage{pgfplots}
\begin{filecontents*}{data.csv}
a,b,c
1,4,1
2,3,2
3,5,3
4,1,4
5,3,5
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[   axis lines=center,view={125}{30},
xlabel={$x_1$}, ylabel=$x_2$,zlabel=$z$,
xtick={1, 2, 3, 4, 5},ymin=0,ymax=5,
xticklabels={\includegraphics[scale=0.05]{example-image-a},\includegraphics[scale=0.05]{example-image-b}, 3, 4, 5},
]
\addplot3+ table [y=a, z=b, x expr=0,col sep=comma] {data.csv};

\addplot3+ [very thick, smooth] table [y=a, z=b, x expr=0,col sep=comma] {data.csv};% to plot curves

\addplot3+ table [x=a, z=c, y expr=0, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}