pgfplots 正在跳过文件中的第一个 ytickslabel

pgfplots 正在跳过文件中的第一个 ytickslabel

渲染 pgfplots 下方的 MWE 会跳过 CSV 的第一个“Adiff”标签。

我确信对于经验丰富的 pgfplots 用户来说,这是一个无需动脑筋且容易获得积分的事情,但我却束手无策。

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable} 

\pgfplotsset{compat=1.11}

\pgfplotsset{every axis legend/.append style={
    at={(0,0)},
    legend cell align=left,
    anchor=north east}}
\pgfplotsset{
  /pgfplots/bar cycle list/.style={
    /pgfplots/cycle list={%
  {black,fill=gray!80,mark=none},%
  {black,fill=gray!50,mark=none},%
  {black,fill=gray!20,mark=none},%
}
},
}

\usepackage{filecontents}

\begin{filecontents}{MoodMeans.csv}
0,1,octant
1,1,Adiff
2,2,Ediff
3,3,Pdiff
4,4,Cdiff
-1,-1,Qdiff
-2,-2,Bdiff
-3,-3,Udiff
-4,-4,Ddiff
\end{filecontents}


\begin{document}

\begin{figure}[!ht]
  \centering
  \begin{tikzpicture}
    \begin{axis}[
    xbar,
    table/col sep=comma,
    title={Mood changes (means)},
    xlabel=Change,
    yticklabels from table={MoodMeans.csv}{octant},
    width=0.9\columnwidth,
    height=9cm,
    bar width=1.8mm,
    /pgf/number format/fixed,
    legend style={
      draw=none,
      at={(0,0)},
      anchor=north east,
      at={(axis description cs:0.5,-0.2)}}
  ]

  \addplot table [y expr=\coordindex, x=0] {MoodMeans.csv};
  \addplot table [y expr=\coordindex, x=1] {MoodMeans.csv};
  \legend{Control,Experiment};

  \draw[ultra thin]
  (axis cs:0, \pgfkeysvalueof{/pgfplots/ymin})
  -- (axis cs:0, \pgfkeysvalueof{/pgfplots/ymax});

\end{axis}
\end{tikzpicture}
\caption{Means of ``mood changes'' for the two groups.\label{fig:moodmeans}}  
\end{figure}
\end{document}

提前致谢

答案1

您的 MWE 中没有\coordindex指定为标签 Adiff 等分配什么 y 值(= 的值)。您必须添加,ytick={0,...,7}因为行计数器从 0 开始。

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable} 

\pgfplotsset{compat=1.11}

\pgfplotsset{every axis legend/.append style={
    at={(0,0)},
    legend cell align=left,
    anchor=north east}}
\pgfplotsset{
  /pgfplots/bar cycle list/.style={
    /pgfplots/cycle list={%
  {black,fill=gray!80,mark=none},%
  {black,fill=gray!50,mark=none},%
  {black,fill=gray!20,mark=none},%
}
},
}

\usepackage{filecontents}

\begin{filecontents}{MoodMeans.csv}
0,1,octant
1,1,Adiff
2,2,Ediff
3,3,Pdiff
4,4,Cdiff
-1,-1,Qdiff
-2,-2,Bdiff
-3,-3,Udiff
-4,-4,Ddiff
\end{filecontents}


\begin{document}

\begin{figure}[!ht]
  \centering
  \begin{tikzpicture}
    \begin{axis}[
    xbar,
    table/col sep=comma,
    title={Mood changes (means)},
    xlabel=Change,
    ytick={0,...,7},% <- added code
    yticklabels from table={MoodMeans.csv}{octant},
    width=0.9\columnwidth,
    height=9cm,
    bar width=1.8mm,
    /pgf/number format/fixed,
    legend style={
      draw=none,
      at={(0,0)},
      anchor=north east,
      at={(axis description cs:0.5,-0.2)}}
  ]

  \addplot table [y expr=\coordindex, x=0] {MoodMeans.csv};
  \addplot table [y expr=\coordindex, x=1] {MoodMeans.csv};
  \legend{Control,Experiment};

  \draw[ultra thin]
  (axis cs:0, \pgfkeysvalueof{/pgfplots/ymin})
  -- (axis cs:0, \pgfkeysvalueof{/pgfplots/ymax});

\end{axis}
\end{tikzpicture}
\caption{Means of ``mood changes'' for the two groups.\label{fig:moodmeans}}  
\end{figure}
\end{document}

在此处输入图片描述

相关内容