# Plots not perfectly aligned vertically [closed]

I created this two plots using pgfplots package and put in the page using subfig package.

This is a part of the code I used to create it.

  \begin{figure}[htp]
\centering
\begin{tikzpicture}[scale=0.8]
\begin{axis}[height=7cm,
x post scale=1.4,
xmin=0,xmax=6000,ymin=0,ymax=3500,
grid=both,
ylabel=Throughput (kbit/s),
/pgf/number format/.cd,
use comma,
1000 sep={},
legend pos = north west,
legend cell align=left,
name=main plot]
{./immagini/throughput_blue.txt};
{./immagini/throughput_green.txt};
\legend{{\footnotesize Network Coding}, {\footnotesize No Network Coding}}
\end{axis}

\begin{axis}[height=3.8cm,
x post scale=1.4,
xmin=0,xmax=6000,ymin=0,ymax=2,
grid=both,
xlabel= Carico offerto totale (kbit/s),ylabel= Guadagno codifica,
/pgf/number format/.cd,
use comma,
1000 sep={},
at={(main plot.below south west)},yshift=-0.1cm,
anchor=north west]
{./immagini/throughput_red.txt};
\end{axis}
\end{tikzpicture}
\caption{Confronto throughput per lo scenario \emph{mobile cloud}}
\label{fig:throughput_nc}
\end{figure}


The problem is, as you can see, the plots are not aligned vertically. I don't undestand the reason.where is the mistake?

-

## closed as too localized by Kurt, lockstep, zeroth, Werner, percusseFeb 16 '13 at 2:55

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

The problem is due to the fact that the labels of the y axis (the numbers) are longer in the first subplot. With pgfplots this is easily solvable with a global setting (one of my questions is about that), but in your case you could solve this by including an invisible node on the left of your figure to shift it to the right. For a more elegant solution it would help to see a stripped down version of your code. –  Vivi Jan 5 '13 at 3:17
As you only use one caption (but two subfloats?) you can simply include both axis environments in one and use TikZ alignments keys (anchor, at, yshift). So the second (lower) axis could have in the options: at={(<upper plot>.below south west)}, anchor=north west, yshift=-<additional padding>; where <upper plot> is the name of the upper plot (option: name=<upper plot>). Check section 4.18 and especially subsection 4.18.4 of the PGFPlots manual (“Alignment Options and Bounding Box Control”/“Horizontal Alignment”). –  Qrrbrbirlbel Jan 5 '13 at 8:57
You may also interested in the groupplots library and its groupplot environment (section 5.5 “Grouping plots”). If you intentionally want to have to tikzpictures (two captions, two floats, pabe-break between both plots (which I wouldn’t recommend as both plots share their x axis)) you’ll have to use something that @Vivi had in mind (empty nodes, minimum widths, \hphantom, …). Anyhow, without the actual axis environments there is not much to help you with. –  Qrrbrbirlbel Jan 5 '13 at 9:04
What, precisely, do you want to center? If you want the left/right axis lines to be centered horizontally, you can exclude any descriptions outside of this range from the bounding box. This can be achieved using \begin{tikzpicture}[trim axis left, trim axis right], compare the pgfplots manual, section alignment. –  Christian Feuersänger Jan 5 '13 at 10:33
You might want to add a % after every { or } which ends a line to avoid a spurious space there. See What is the use of percent signs (%) at the end of lines? for the details. Such things can influence the horizontal alignment. –  Martin Scharrer Jan 5 '13 at 11:02