2

I want to increase the vertical separation between these two graphs. However, yshift seems to have no effect (I used it in the axis of the second graph). How can I increase separation between the graphs?

Code:

\documentclass{article}
\usepackage{pgfplots,pgfplotstable}
\begin{document}
\begin{tikzpicture}
  \pgfplotstableread[col sep=comma]{
    x,y1,y2
    float,175944298.68799999,338106119.66
    int,199884427.252,387109111.47600001
    large int,320234228.36400002,386832494.94400001
    string,387167693.32999998,575491284.27999997
    unicode,522103953.7,574848336.48
    mixed,343280219.736,338146080.088
  }\mydata

  \begin{axis}[
    title=Time to Sort Random Lists by Type,
    ymin=0,
    symbolic x coords={float,int,string,large int,unicode,mixed},
    xtick=data,
    ylabel=CPU Cycles,
    ybar=5pt,% configures `bar shift'
    bar width=9pt,
    width = 0.95\textwidth,
    height= 0.75\textwidth
    ]

    \addplot[fill=red!70] table[x=x,y=y1] {\mydata};
    \addplot[fill=blue!70] table[x=x,y=y2] {\mydata};

    \addplot [
    only marks,
    point meta=explicit,
    nodes near coords={\pgfmathprintnumber[precision=1]{\pgfplotspointmeta}\%},
    nodes near coords style={above}
    ]
    table[
    x=x,
    y expr={max(\thisrow{y1},\thisrow{y2})},
    meta expr={(1-\thisrow{y1}/\thisrow{y2}) * 100}] {\mydata};



  \end{axis}
\end{tikzpicture}

  \begin{tikzpicture}
            \pgfplotstableread[col sep=comma]{
              x,y1,y2
              float,260590831.868,708663977.83599997
              int,286399925.28899997,812578839.09200001
              large int,404332394.89099997,812970977.40799999
              string,488786289.75599998,1105214209.184
              unicode,612542047.692,1096601246.084
              mixed,414990734.64399999,709336654.08800006
            }\mydata

            \begin{axis}[
              title=Time to Sort Random Lists of Tuples by Type,
              ymin=0,
              symbolic x coords={float,int,string,large int,unicode,mixed},
              xtick=data,
              ylabel=CPU Cycles,
              ybar=5pt,
              bar width=9pt,
              width = 0.95\textwidth,
              height= 0.75\textwidth,
              yshift=10cm %DOESN'T WORK!!!
              ]

              \addplot[fill=red!70] table[x=x,y=y1] {\mydata};
              \addplot[fill=blue!70] table[x=x,y=y2] {\mydata};

              \addplot [
              only marks,
              point meta=explicit,
              nodes near coords={\pgfmathprintnumber[precision=1]{\pgfplotspointmeta}\%},
              nodes near coords style={above}
              ]
              table[
              x=x,
              y expr={max(\thisrow{y1},\thisrow{y2})},
              meta expr={(1-\thisrow{y1}/\thisrow{y2}) * 100}] {\mydata};



            \end{axis}
          \end{tikzpicture}


\end{document}

enter image description here

  • The coordinates inside a tikzpicture is only relative to the tikzpicture itself, so if yshift does anything at all there, it just adds 10cm to every y-coordinate. But because the tikzpicture is always cropped to its contents, it doesn't matter if the internal coordinates span from y=0 to y=10, or from y=-200 to y=-190. LaTeX just sees a box that is 10 high, and places it on the page accordingly. – Torbjørn T. Feb 28 '17 at 07:07

2 Answers2

3

You can add some vertical space between these two pictures

\documentclass{article}
\usepackage{pgfplots,pgfplotstable}
\begin{document}
\begin{tikzpicture}
  \pgfplotstableread[col sep=comma]{
    x,y1,y2
    float,175944298.68799999,338106119.66
    int,199884427.252,387109111.47600001
    large int,320234228.36400002,386832494.94400001
    string,387167693.32999998,575491284.27999997
    unicode,522103953.7,574848336.48
    mixed,343280219.736,338146080.088
  }\mydata

  \begin{axis}[
    title=Time to Sort Random Lists by Type,
    ymin=0,
    symbolic x coords={float,int,string,large int,unicode,mixed},
    xtick=data,
    ylabel=CPU Cycles,
    ybar=5pt,% configures `bar shift'
    bar width=9pt,
    width = 0.95\textwidth,
    height= 0.75\textwidth
    ]

    \addplot[fill=red!70] table[x=x,y=y1] {\mydata};
    \addplot[fill=blue!70] table[x=x,y=y2] {\mydata};

    \addplot [
    only marks,
    point meta=explicit,
    nodes near coords={\pgfmathprintnumber[precision=1]{\pgfplotspointmeta}\%},
    nodes near coords style={above}
    ]
    table[
    x=x,
    y expr={max(\thisrow{y1},\thisrow{y2})},
    meta expr={(1-\thisrow{y1}/\thisrow{y2}) * 100}] {\mydata};



  \end{axis}
\end{tikzpicture}
\vskip 3em\relax
  \begin{tikzpicture}
            \pgfplotstableread[col sep=comma]{
              x,y1,y2
              float,260590831.868,708663977.83599997
              int,286399925.28899997,812578839.09200001
              large int,404332394.89099997,812970977.40799999
              string,488786289.75599998,1105214209.184
              unicode,612542047.692,1096601246.084
              mixed,414990734.64399999,709336654.08800006
            }\mydata

            \begin{axis}[
              title=Time to Sort Random Lists of Tuples by Type,
              ymin=0,
              symbolic x coords={float,int,string,large int,unicode,mixed},
              xtick=data,
              ylabel=CPU Cycles,
              ybar=5pt,
              bar width=9pt,
              width = 0.95\textwidth,
              height= 0.75\textwidth,
              yshift=10cm %DOESN'T WORK!!!
              ]

              \addplot[fill=red!70] table[x=x,y=y1] {\mydata};
              \addplot[fill=blue!70] table[x=x,y=y2] {\mydata};

              \addplot [
              only marks,
              point meta=explicit,
              nodes near coords={\pgfmathprintnumber[precision=1]{\pgfplotspointmeta}\%},
              nodes near coords style={above}
              ]
              table[
              x=x,
              y expr={max(\thisrow{y1},\thisrow{y2})},
              meta expr={(1-\thisrow{y1}/\thisrow{y2}) * 100}] {\mydata};



            \end{axis}
          \end{tikzpicture}


\end{document}
Ice0cean
  • 1,646
3

If you have both axis environments in the same tikzpicture environment, yshift does work, Adjust -9.5cm to your liking.

(Sidenote: For multiple axes in the same figure, like here, the groupplots library can be useful.)

\documentclass{article}
\usepackage{pgfplots,pgfplotstable}
\begin{document}
\begin{tikzpicture}
  \pgfplotstableread[col sep=comma]{
    x,y1,y2
    float,175944298.68799999,338106119.66
    int,199884427.252,387109111.47600001
    large int,320234228.36400002,386832494.94400001
    string,387167693.32999998,575491284.27999997
    unicode,522103953.7,574848336.48
    mixed,343280219.736,338146080.088
  }\mydata

  \begin{axis}[
    title=Time to Sort Random Lists by Type,
    ymin=0,
    symbolic x coords={float,int,string,large int,unicode,mixed},
    xtick=data,
    ylabel=CPU Cycles,
    ybar=5pt,% configures `bar shift'
    bar width=9pt,
    width = 0.95\textwidth,
    height= 0.75\textwidth
    ]

    \addplot[fill=red!70] table[x=x,y=y1] {\mydata};
    \addplot[fill=blue!70] table[x=x,y=y2] {\mydata};

    \addplot [
    only marks,
    point meta=explicit,
    nodes near coords={\pgfmathprintnumber[precision=1]{\pgfplotspointmeta}\%},
    nodes near coords style={above}
    ]
    table[
    x=x,
    y expr={max(\thisrow{y1},\thisrow{y2})},
    meta expr={(1-\thisrow{y1}/\thisrow{y2}) * 100}] {\mydata};



  \end{axis}

            \pgfplotstableread[col sep=comma]{
              x,y1,y2
              float,260590831.868,708663977.83599997
              int,286399925.28899997,812578839.09200001
              large int,404332394.89099997,812970977.40799999
              string,488786289.75599998,1105214209.184
              unicode,612542047.692,1096601246.084
              mixed,414990734.64399999,709336654.08800006
            }\mydata

            \begin{axis}[
              title=Time to Sort Random Lists of Tuples by Type,
              ymin=0,
              symbolic x coords={float,int,string,large int,unicode,mixed},
              xtick=data,
              ylabel=CPU Cycles,
              ybar=5pt,
              bar width=9pt,
              width = 0.95\textwidth,
              height= 0.75\textwidth,
              yshift=-9.5cm % works
              ]

              \addplot[fill=red!70] table[x=x,y=y1] {\mydata};
              \addplot[fill=blue!70] table[x=x,y=y2] {\mydata};

              \addplot [
              only marks,
              point meta=explicit,
              nodes near coords={\pgfmathprintnumber[precision=1]{\pgfplotspointmeta}\%},
              nodes near coords style={above}
              ]
              table[
              x=x,
              y expr={max(\thisrow{y1},\thisrow{y2})},
              meta expr={(1-\thisrow{y1}/\thisrow{y2}) * 100}] {\mydata};



            \end{axis}
\end{tikzpicture}

\end{document}
Torbjørn T.
  • 206,688