I'm trying to create a two graph Figure with pgfplots
. However, the result is not exactly what I want, because I expected the two graphs to appear side by side, but they are oddly aligned instead. In the pgfplot
manual (p. 21) one can read
and, therefore, I don't know what I'm doing wrong.
My code is
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat = newest}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
ticks=none,
axis x line=bottom,
axis y line=left,
xmin=0,xmax=7,
ymin=0,ymax=12]
\addplot[
domain = 0:7,
samples =200,
] {x};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
ticks=none,
axis x line=bottom,
axis y line=left,
axis y discontinuity=crunch,
xmin=0,xmax=1.3,
ymin=0.5,ymax=1.3]
\addplot[
domain = 0:sqrt(1/3),
samples =200,
] {sqrt(7/6-x^2)};
\addplot[
domain = sqrt(1/3):sqrt(7/6),
fill = gray,
fill opacity = 0.1,
samples =200,
y filter/.expression={x==sqrt(7/6 )?0:y},
] {sqrt(7/6-x^2)}\closedcycle;
\addplot[
domain = 0:7,
samples =200,
] {sqrt(5/6)};
\fill[gray, opacity = 0.1] (0,0) -- (0,0.9129) -- (0.5774,0.9129) -- (0.5774,0);
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
Edit: Is it, perhaps, a consequence of the crunch
of the axis in the rightmost graph? I think it is: removing axis y discontinuity=crunch
results in the two graphs being aligned.
Adding \usepackage{showframe}
shows that the resulting Figure is wider than the margins even when the two diagrams are correctly aligned. However, the misalignement persists when the crunch
is present even if the size of the individual plots is reduced to have them fit in the page width.
Best Answer
\usepgfplotslibrary{groupplots}
.Remark:
\usepackage{showframe}
shows that your diagrams are too wide.