1

I thought that the option height passed to \nextgroupplot is what i needed but it's not. As you can probably see in the picture, the second plot isn't two times the height of the first one. So how can I have the second plot two times the height of the first one?

Bonus: To be precise, what I would is that a distance of 1 along the y axis of the first plot is the same as a distance of 1 along the y axis of the second plot.

\documentclass[]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
  group style={
    group size=1 by 2,
    vertical sep=12pt,
    group name=G},
  axis x line=center, axis y line=center,
  xmin = 0, xmax = 4.2
]
\nextgroupplot[
  width = \textwidth, height = 0.2*\textwidth,
  ymin = 0, ymax = 1.2
]
\draw (0,0) 
  -| (.75,1) -| (1,0) 
  -| (1.75,1) -| (2,0) 
  -| (2.75,1) -| (3,0) 
  -| (3.75,1) -| (4,0) 
  -| (4.75,1) -| (5,0);
\nextgroupplot[
  width = \textwidth, height = 0.4*\textwidth,
  ymin = -1.2, ymax = 1.2
]
\draw (0,1) 
  -| (.75,-1) -| (1,1) 
  -| (1.75,-1) -| (2,1) 
  -| (2.75,-1) -| (3,1) 
  -| (3.75,-1) -| (4,1) 
  -| (4.75,-1) -| (5,1);
\end{groupplot}
\end{tikzpicture}
\end{document}

example_image

2

I think you are looking for unit vector ratio. This makes sure that the y units have the same meaning in both plots. As mentioned by Torbjørn T. in the comments in this question, the height means height including everything, also tick labels.

\documentclass[]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
  group style={
    group size=1 by 2,
    vertical sep=12pt,
    group name=G},
  axis x line=center, axis y line=center,
  xmin = 0, xmax = 4.2,unit vector ratio=2 1,width = \textwidth
]
\nextgroupplot[
  ymin = 0, ymax = 1.2
]
\draw (0,0) 
  -| (.75,1) -| (1,0) 
  -| (1.75,1) -| (2,0) 
  -| (2.75,1) -| (3,0) 
  -| (3.75,1) -| (4,0) 
  -| (4.75,1) -| (5,0);
\nextgroupplot[
  ymin = -1.2, ymax = 1.2
]
\draw (0,1) 
  -| (.75,-1) -| (1,1) 
  -| (1.75,-1) -| (2,1) 
  -| (2.75,-1) -| (3,1) 
  -| (3.75,-1) -| (4,1) 
  -| (4.75,-1) -| (5,1);
\end{groupplot}
\end{tikzpicture}
\end{document}

enter image description here

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.