我正在为我的条形图绘制重要性标记(使用 pgfplots 为图表添加重要标记)。在用户的帮助下,我设法按照自己想要的方式绘制了箭头。代码在我的工作示例中运行良好,但当我将其放入原始文件中时,它无法编译并显示以下错误消息:
! Package pgfplots Error: Sorry, the input coordinate `0' has not been defined with 'symbolic x coords={Baseline,Stimulus}... Maybe it has been misspelled? Or did you mean something like [normalized]0?
我现在发现问题似乎出在 \pgfplotsset{compat=1.13} 命令上。当我将此命令(位于我的原始文件中)放入工作示例中时,它无法编译并给出相同的错误警告。
您知道如何解决这个问题吗?如果我的原始文件中没有 \pgfplotsset{compat=1.13} 命令,所有图表看起来都很奇怪,所以我不想删除它。
这是我的工作示例:
\documentclass{apa6}
\usepackage{pgfplots}
%%% if you delete this command (below), the file compiles:
\pgfplotsset{compat=1.13}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
height=0.7\textwidth,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={Pupillenweite},
symbolic x coords={Baseline,Stimulus},
xtick=data,
]
%neutral
\addplot[blue,fill=blue!30!white,error bars/.cd,y dir=both,y explicit,]
coordinates{(Baseline,0.0476) +-(0.02117,0.02117) (Stimulus,-0.1809) +-(0.01841,0.01841)};
%negativ
\addplot[red,fill=red!30!white,error bars/.cd,y dir=both,y explicit,]
coordinates{(Baseline,0.0342) +-(0.02073,0.02073) (Stimulus,0.1013) +-(0.01904,0.01904)};
%significance
\draw [arrows={Bar[left]-Bar[right]}, shorten <= -10pt, shorten >=5pt]
(axis cs:Baseline,0.1) -- node[midway, above]{*} (axis cs:Stimulus,0.1);
\draw [arrows={Bar[left]-Bar[right]}, ]
(axis cs:Stimulus,0.15) ++(-10pt, 0) -- node[midway, above]{*} ++(30pt,0);
\draw [arrows={Bar[left]-Bar[right]}, shorten <= 5pt, shorten >=-5pt]
(axis cs:Baseline,0.13) -- node[midway, above]{*} (axis cs:Stimulus,0.13);
\legend{neutral,emotional}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
第二个 \draw 命令包括对起始坐标++(-10pt, 0)
和结束坐标的修改++(30pt,0)
。但是,这两个实例中 y 坐标都缺少单位说明符。因此,此\draw
命令需要写成:
\draw [arrows={Bar[left]-Bar[right]}]
(axis cs:Stimulus,0.15) ++(-10pt,0pt) --
node[midway, above]{*} ++(30pt,0pt);
结果如下:
这是 MWE:
\documentclass{apa6}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13} % and above
\usetikzlibrary{arrows.meta}
\pagestyle{empty} % remove page number
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
height=0.7\textwidth,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={Pupillenweite},
symbolic x coords={Baseline,Stimulus},
xtick=data,
]
%neutral
\addplot[blue,fill=blue!30!white,error bars/.cd,y dir=both,y explicit,]
coordinates{(Baseline,0.0476) +-(0.02117,0.02117) (Stimulus,-0.1809) +-(0.01841,0.01841)};
%negativ
\addplot[red,fill=red!30!white,error bars/.cd,y dir=both,y explicit,]
coordinates{(Baseline,0.0342) +-(0.02073,0.02073) (Stimulus,0.1013) +-(0.01904,0.01904)};
%significance
\draw [arrows={Bar[left]-Bar[right]}, shorten <= -10pt, shorten >=0pt]
(axis cs:Baseline,0.1) -- node[midway, above]{*} (axis cs:Stimulus,0.1);
\draw [arrows={Bar[left]-Bar[right]}, ]
(axis cs:Stimulus,0.15) ++(-10pt,0pt) -- % add pt to the y-coordinate
node[midway, above]{*} ++(30pt,0pt); % add pt to the y-coordinate
\draw [arrows={Bar[left]-Bar[right]}, shorten <= 5pt, shorten >=-5pt]
(axis cs:Baseline,0.13) -- node[midway, above]{*} (axis cs:Stimulus,0.13);
\legend{neutral,emotional}
\end{axis}
\end{tikzpicture}
\end{document}