pgfplots 轴不响应 yshift

pgfplots 轴不响应 yshift

我想增加这两个图之间的垂直间距。但是,yshift似乎没有效果(我在axis第二张图中使用了它)。我怎样才能增加图之间的间距?

代码:

\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}

在此处输入图片描述

答案1

如果您axis在同一个环境中拥有这两种环境tikzpictureyshift那么确实可以工作,请-9.5cm根据您的喜好进行调整。

(旁注:对于同一张图中的多个轴,像这里一样,该groupplots库很有用。)

\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}

答案2

您可以在这两张图片之间添加一些垂直空间

\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}

相关内容