0

I've been trying to make a ybar plot with error bar using pgfplots. I want to make this graph inside a tex template, but one weird thing has occurred - when I inserted the following code (be more specific - inserted only tikzpicture and its content) into the template this error message occurred:

! Use of \pgfplots@foreach@plot@coord@NEXT@plusminus doesn't match its definition.

\documentclass[10pt]{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.5.1}

\begin{document}
\begin{tikzpicture}
\begin{axis} [%log ticks with fixed point
,symbolic x coords={Lighting,Computers,Total}]
\addplot+[only marks] plot[error bars/.cd, y dir=both, y explicit]
coordinates{
    (Lighting,0.12) +- (0.31,0.03)
    (Computers,0.06) +- (0.12,0.01) 
    (Total,0.07) +- (0.14,0.02)
};
\end{axis} 
\end{tikzpicture}

\end{document}

(The code is taken from pgfplots with symbolic x coords and error bars .)

When I inserted this code into a separate tex file, everything works fine and it produced a graph.

I know that one solution is to make the graph in an external file and then import it, but I am asking what can cause this error message (I'm still novice to tex, yet read manual for pgfplots) and if there is a way to get it to work.

I've tried to google it but found nothing. Also I've tried to change order of items in the preamble in the main file. The preamble looks like this:

\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath,amssymb,verbatim}
\usepackage{txfonts, cleveref}
\usepackage[linesnumbered]{algorithm2e}
\usepackage{multirow}
\usepackage{array}
\usepackage{float}

\usepackage{pgfplotstable}
\usepackage{caption}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5.1}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usetikzlibrary{patterns}

I'm intentionally not posting the template because it would be simpler to import the graph from external file for me than for someone to read through a template.

4
  • 1
    but then we don't know what might go wrong because it works as it is. Also current version of pgfplots is 1.10
    – percusse
    Aug 5 '14 at 21:19
  • Sometimes packages modify characters such that they do stuff ("become active"). You might help us to identify if this is the root cause by adding \catcode\-=12 somewhere before the offending plot (or the offending figure). This will restore the character handling for -. If this is the case, we have to identify the package which redefined the -` char. Aug 6 '14 at 21:19
  • Ch. Feuersänger - great it works! Thansk for support. I tried to comment other packages and the bug seems to be inside the template. percusse - However, I was unable to upload the whole template on writelatex.
    – Ell
    Aug 7 '14 at 12:26
  • @ChristianFeuersänger Hi, apparently your solution worked. Want to make it an answer and take the Q off the list of unanswered?
    – Johannes_B
    Feb 11 '15 at 21:58
2

The problem is causes by catcode reassignments in the template: some code changes uses something like

\catcode\-=13

which causes TeX to change the meaning of the minus character -. Any occurrence of this character will be different from before -- and pgfplots uses it inside of the error bar input specification.

The solution is to change it back before using pgfplots (by means of \catcode\-=12) or by eliminating the catcode hackery.

Note that catcode changes inherently cause problems of this sort and are generally not a good practise. There are cases where their use outweighs their price (namely incompatibility with lots of other packages). But if possible: refrain from catcode changes.

1
  • 1
    If the document loads babel for Czech or Slovak, the hyphen becomes a shortcut and will cause the mentioned problem. If PGF version 3.0.0 is used, \usetikzlibrary{babel} will solve the issue in this case.
    – egreg
    Feb 12 '15 at 22:38

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.