5

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

enter image description here

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]
                \addplot[smooth,thick,blue!70]
                    table[x=load,y=throughput]
                    {./immagini/throughput_blue.txt};
                \addplot[smooth,thick,green!70]
                    table[x=load,y=throughput]
                    {./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]
                \addplot[smooth,thick,red!70]
                    table[x=load,y=gain]
                    {./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?

Mazzy
  • 7,642
  • How did you manage to extract the data from the figure in the end? – Vivi Jan 05 '13 at 03:11
  • 2
    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 05 '13 at 03:17
  • 3
    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 05 '13 at 08:57
  • 2
    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 05 '13 at 09:04
  • 1
    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 05 '13 at 10:33
  • 2
    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 05 '13 at 11:02
  • @Qrrbrbirlbel I resolved through your suggest...Thanks so much...the only strange thing is I got error when use yshift option. Do you know why? – Mazzy Jan 05 '13 at 13:21
  • @Mazzy No, how could I? I know neither the error (message? wrong output?) nor your source. – Qrrbrbirlbel Jan 05 '13 at 13:23
  • This is the error I got: pgfkeys: I do not know the key '/pgf/number format/yshift' and I am going to ignore it. Perhaps you misspelled it. \end{axis} – Mazzy Jan 05 '13 at 13:32
  • I posted the code – Mazzy Jan 05 '13 at 13:36
  • 1
    @Mazzy Well, the error message says it all. You have used /pgf/number format/.cd that changes how PGF keys work. Move yshift (and everything else that does not belong to the /pgf/number format/ tree) in front of that. PS: Use for example @Qrrbrbirlbel in your comment to address a specific user (as I did in this comment) so that they get a notification. – Qrrbrbirlbel Jan 05 '13 at 13:41
  • @Qrrbrbirlbel Yeah it worked...thanks so much!!! – Mazzy Jan 05 '13 at 13:50
  • @Mazzy Do you want to post a final MWE so that we can see how you solved your problem? Is this a duplicate of Aligning subplots in a pgfplots figure? – Qrrbrbirlbel Jan 07 '13 at 14:31

0 Answers0