26

I am trying to create a very basic bar chart using pgfplots. I need four bars representing percentages with text as labels under the x axis. Text labels contain spaces and accented, non-English characters.

Since I use pgfplots for all other charts in my paper I thought I'd give a shot at this one, too. However, since this chart uses non-numeric x values it's a little tricky. I'm trying to start with a text book example and go from there. Here's the example from the pgfplots manual (4.20.1 on p. 210) I'm trying to use:

\documentclass[12pt,a4paper,oneside]{article}

\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.3}

\begin{document}

\begin{tikzpicture}
\begin{axis}[symbolic x coords={a,b,c,d,e,f,g,h,i}]
\addplot+[smooth] coordinates {
(a,42)
(b,50)
(c,80)
(f,60)
(g,62)
(i,90)};
\end{axis}
\end{tikzpicture}

\end{document}

I have major problems with this code. For starters, TeXmaker hangs while trying to compile, I have to kill the pdflatex process to reanimate it. When I do I get the following error messages:

! Package pgfkeys Error: I do not know the key '/pgfplots/compat' and I am goin g to ignore it. Perhaps you misspelled it.

! Package PGF Math Error: Could not parse input 'a' as a floating point number, sorry. The unreadable part was near 'a'..

If someone could shed some light on what I'm doing wrong I'd most appreciate it. I am using a recent version of Ubuntu and TeX Live (2009-10). I have been using them for a year or so, never had a hang issue so far.

Recommendations for any other solution (preferably without any external program) are also welcome and appreciated. Thanks.

Heisenb0rg
  • 2,153

2 Answers2

29

The version of pgfplots that is included in Ubuntu 10.10 is 1.2.2. Apparently the feature that you are using was added between then and version 1.4.1 (which is the current version).

Unless someone comes up with a workaround to add text coordinates in pgfplot 1.2, the easiest option for you is probably to upgrade to TeX Live 2010. Installing it manually isn't too hard and you will get all the newest versions. PGF related packages changed a lot since the TeX Live version that is included in Ubuntu. Also, you will be able to run tlmgr update --self --all to update your TeX installation at any time.


Here is a proof-of-concept with version 1.4 (I don't know pgfplots well, so there might be a better way to do this):

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    symbolic x coords={a small bar,a medium bar,a large bar},
    xtick=data]
    \addplot[ybar,fill=blue] coordinates {
        (a small bar,42)
        (a medium bar,50)
        (a large bar,80)
    };
\end{axis}
\end{tikzpicture}

\end{document}

example

Caramdir
  • 89,023
  • 26
  • 255
  • 291
  • Thank you, Caramdir. I will see if I can upgrade my TeX Live. – Heisenb0rg Jan 09 '11 at 18:14
  • I'm new to this UI... I press enters way too often. So, Caramdir, would you be able to say if it is possible to draw the chart I mention in my original question using TeX Live 2010 and pgfplots? Thanks. – Heisenb0rg Jan 09 '11 at 18:21
  • @Heisenb0rg: Yes. – Alan Munn Jan 09 '11 at 18:28
  • Thank you, Alan. I'll give it a try and see if I can do it. – Heisenb0rg Jan 09 '11 at 18:30
  • @Heisenb0rg, see the edited answer. – Caramdir Jan 09 '11 at 18:48
  • @Caramdir: This is exactly what I need, nothing fancy. Thanks again. – Heisenb0rg Jan 09 '11 at 19:04
  • @Caramdir, Alan: installed latest TeX Live 2010, and the chart is drawn and displayed perfectly. Thank you. – Heisenb0rg Jan 10 '11 at 09:43
  • If you'd rather not install manually, note that a newer version will ship with Ubuntu 12.10, and there are 12.04 backports in a PPA - see this bug report: https://bugs.launchpad.net/ubuntu/+source/texlive-base/+bug/712521 and this ppa: https://launchpad.net/~texlive-backports/+archive/ppa - just add it to your software sources. Then you can install the necessary packages from there. – Steve Kroon Sep 13 '12 at 06:56
6

As a small sidenote: Updating pgfplots to 1.4.1 (on Ubuntu Natty, texlive 2009) while leaving the rest of the packages unaltered, did not resolve this issue for me. Installing a completely separately texlive 2010 did resolve the issue. I was trying the "lazy" approach first... so, for all other lazy people: no need to try this, go with the correct solution as proposed by Caramdir. Btw... Thanks.