4

I am working on drawing significance markers to my bar chart (Adding significance markers to graphs with pgfplots). With the help of an user, I managed to draw the arrows just the way I wanted them. The code run well in my working example, but when I put it in my original file, it wouldn't compile and give this error message:

! 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?

I now found out that the problem seems to be the \pgfplotsset{compat=1.13} command. When I put this (which is in my original file) into the working example, it wouldn't compile and give the same error warning.

Do you have any idea of how to solve this problem? Without the \pgfplotsset{compat=1.13} command in my original file, all the graphs look really weird, so I don't want to delete it.

Here is my working example:

        \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}
  • 2
    Is this what you need? Change ++(-10pt, 0) to ++(-10pt, 0pt) and ++(30pt,0) to ++(30pt,0pt). The y-coordinates are missing the unit specified pt? The current pgfplots version is 1.15. – Ross Sep 26 '17 at 8:19
  • 2
    @Ross' comment solves the problem it seems. It's probably somehow caused by the fact that with compat=1.11 or higher, axis cs is the default coordinate systems, so in (10pt,0), the 0 is read in axis units I think. Why the y-coordinate would cause a problem with symbolic *x* coordinates on the other hand, that I don't understand. – Torbjørn T. Sep 26 '17 at 8:26
  • 1
    @TorbjørnT. I can only find one example in the manual that uses \draw[options] (first co-ordinate) -- ++(x units,y units). It is on p329. With ++(x units, as the preface to the y value, it is expecting the y value to also have a unit specifier, which could be pt, cm or whatever). That's how I interpret it. – Ross Sep 26 '17 at 8:39
  • Thanks a lot, Ross' comment solves the problem! Do you know how I can tag the question as answered when there are only comments? – Anne B. Sep 26 '17 at 8:49
  • 1
    @Ross Sure, you obviously need the unit, but the error message seems to indicate that the 0 is seen as an x-coordinate, which is what I don't get. Anne: You can't accept a comment, but Ross can/should write up a proper answer, which you can then accept. – Torbjørn T. Sep 26 '17 at 8:50
3

The second \draw command includes modifications to the start co-ordinate ++(-10pt, 0) and end co-ordinate ++(30pt,0). However, the unit specifier is missing for the y-coordinate in both instances. Thus, this \draw command needs to be written as:

\draw [arrows={Bar[left]-Bar[right]}] 
    (axis cs:Stimulus,0.15) ++(-10pt,0pt) -- 
     node[midway, above]{*} ++(30pt,0pt);

This is the result:

enter image description here

This is the 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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.