0

I want to plot two 3D functions using \addplot3. Both plots are defined within two separated axis environments (plotting them within the same axis produced worse results). I want to change the position where the plots are displayed. Currently, Plot 2 is displayed on top of Plot 1 (covering it). I want Plot 2 to be displayed above Plot 1. In the code below, I added an ellipse with the exact position I want each plot to be.

I tried using at={(x,y)} with the expected position as an option for the axis, but it didn't work.

\documentclass{article}
\usepackage{graphicx}
\usepackage{algorithmic}
\usepackage{rotating}
\usepackage{tikz}
\usepackage{pgfplots}


\begin{document}

\begin{tikzpicture}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Expected Position
\draw (3.43,2.55)[very thick] ellipse (1.02in and 0.515in);
% Plot 1
\begin{axis}[axis equal, xmin=-1,xmax=1,ymin=-1,ymax=1,zmin=0,zmax=1,hide axis]
\addplot3[surf,z buffer=sort,colormap={}{rgb255(0cm)=(0,128,0); rgb255(1cm)= (255,255,0);color(2cm)=(orange)}, samples=30,domain=0:1,y domain=0:2*pi]
({x * cos(deg(y))},
 {x* sin(deg(y))},
 {exp(-sqrt((x * cos(deg(y)))^2 + (x* sin(deg(y)))^2))}
);
\end{axis}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Expected Position
\draw (3.43,6.0)[very thick] ellipse (1.02in and 0.515in);
% Plot 2
\begin{axis}[axis equal, xmin=-1,xmax=1,ymin=-1,ymax=1,zmin=2,zmax=3,hide axis]
\addplot3[surf,z buffer=sort, samples=30,domain=0:1,y domain=0:2*pi]
({x * cos(deg(y))},
 {x* sin(deg(y))},
 {-x^2+3}
 );
\end{axis}
\end{tikzpicture}
\end{document}

The current outcome is the following: enter image description here

0

You can use the grouplots environment which, of course, groups plots. You can choose to display horizontally and vertically, with the distance you want.

If you want the plot 2 to appear above, then you can list it first in the code. I left the command for the legend if you want, just uncomment it to use it.

Output

enter image description here

Code

\documentclass[margin=10pt]{standalone}
\usepackage{graphicx}
\usepackage{algorithmic}
\usepackage{rotating}
\usepackage{tikz}
\usepackage{pgfplots}

\usepgfplotslibrary{groupplots}

\pgfplotsset{compat=1.13}

\begin{document}
\begin{tikzpicture}
\begin{groupplot}[%
    group style={group size= 1 by 2, vertical sep=0cm,},
    height=5cm,width=6.4cm,
    %legend entries = {plot1,plot2}
    ]

% Plot 2
\nextgroupplot[axis equal, xmin=-1,xmax=1,ymin=-1,ymax=1,zmin=2,zmax=3,hide axis]
\addplot3[surf,z buffer=sort, samples=30,domain=0:1,y domain=0:2*pi]
({x * cos(deg(y))},
 {x* sin(deg(y))},
 {-x^2+3}
 );

% Plot 1
\nextgroupplot[axis equal, xmin=-1,xmax=1,ymin=-1,ymax=1,zmin=0,zmax=1,hide axis]
\addplot3[surf,z buffer=sort,colormap={}{rgb255(0cm)=(0,128,0); rgb255(1cm)= (255,255,0);color(2cm)=(orange)}, samples=30,domain=0:1,y domain=0:2*pi]
({x * cos(deg(y))},
 {x* sin(deg(y))},
 {exp(-sqrt((x * cos(deg(y)))^2 + (x* sin(deg(y)))^2))}
);
\end{groupplot}
\end{tikzpicture}
\end{document}
| improve this answer | |
  • Is there any way of controlling the space between the plots? – totalUnimodular May 3 '16 at 23:39
  • @totalUnimodular yes, the value vertical space=0cm can also be negative. That way it will be even smaller than my example. – Alenanno May 3 '16 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.