# Maths expression in coordinates for a bar chart

I am using pgfplots to create a bar chart, with the x-axis representing different categories. Using symbolic x coords I can specify the labels for the categories. However, I am unable to use a mathematical expression to define the height of the bars (y coordinate). I suspect that this is related to the use of symbolic x coords.

Here's a minimum (non-)working example:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[symbolic x coords={a,b,c,d,e,f}]
(a, 1*2)
(b, 2*2)
(c, 3*2)
(d, 4*2)
(e, 5*2)
(f, 6*2)
};
\end{axis}
\end{tikzpicture}

\end{document}


The error I receive when compiling with pdflatex is:

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

Any help would be greatly appreciated.

-

You're right, the symbolic coordinates switches off the math parser because it wouldn't work with the symbolic coordinates, and it cannot be enabled selectively for the y coordinates.

It looks like you will have to work around it. Depending on how you generate the data for plotting, this might or might not be an acceptable solution - if you only need a couple of data points that you input by hand, this should work fine.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[xticklabels={a,b,c,d,e,f},
xtick={1,...,6}, % To make sure the tick labels match the data points
xticklabel style={text height=2ex}] % Make all letters the same height so they align properly
(1, 1*2)
(2, 2*2)
(3, 3*2)
(4, 4*2)
(5, 5*2)
(6, 6*2)
};
\end{axis}
\end{tikzpicture}

\end{document}


-
Thank you, this is a rather nice solution. –  Andrew Ho Feb 15 '11 at 23:23