2

I have seen the previous posts regarding "bar chart with text as x axis labels". I tried to use the same code discussed in the posts and in the documentation,

\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}

Unfortunately i did get the required result. I am using ubuntu Mevrick. Could any one guide me how i can plat the bar graphs having x axis labels

Hendrik Vogt
  • 37,935

1 Answers1

2

The code you posted should result in a smoothed line plot. You want the option ybar instead of smooth in the \addplot line. Here's a complete example:

\documentclass{minimal}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}

\begin{axis}[symbolic x coords={a,b,c,d,e,f,g,h,i},
xtick={a,b,c,d,e,f,g,h,i},  % Use this to decide which tickmarks to print
xticklabel style={text height=2ex}, % This aligns all letters on the same line, if it is missing, 'a' and 'b' are at different heights
ymin=0] 

\addplot[ybar,fill] coordinates {
(a,42)
(b,50)
(c,80)
(f,60)
(g,62)
(i,90) };

\end{axis}

\end{tikzpicture}
\end{document}

column plot with text x axis labels

Jake
  • 232,450
  • I used your code this time but i got only a frame without any graphs the values on x-axis are,

    0 0.2 0.4 0.6 0.8 11 1

    –  Jan 24 '11 at 14:16
  • @survivor You probably have an outdated version of pgfplots. See this answer for details. – Jake Jan 24 '11 at 14:24
  • @survivor: I am using Ubuntu Maverick with the latest TeX Live 2010 (not the version that comes with the distribution) and Jake's sample code works perfectly. Dig deeper. – Heisenb0rg Jan 24 '11 at 14:31
  • I used the under given link for upgrading PGFplots, –  Jan 24 '11 at 14:54
  • Could you please tell me how i can verify that the version i am using is updated or not? –  Jan 24 '11 at 14:56
  • 1
    @survivor: if you use the version of TeX Live that comes with your Ubuntu distribution then it's TeX Live 2009 with pgfplots 1.2.2, I think. The command is "dpkg -l texlive*", mind the first column with the status values. To get the latest version, you need to remove TeX Live 2009 and install the latest version from here: http://www.tug.org/texlive/ It works flawlessly on Ubuntu Maverick. – Heisenb0rg Jan 24 '11 at 15:19
  • add \listfiles as the very first command of your tex-file. run pdflatex and then have a look in the log file which is created in the same folder as the tex-file. The log-file contains a File List and states all used packages and versions. You have been pointed towards \listfiles in the pgfplots mailing list as well. In case the package is outdated, you can manually update it – Martin H Jan 24 '11 at 16:37
  • @survivor: also have a look at this question about upgrading to TeXLive 2010. – Juan A. Navarro Jan 24 '11 at 16:39
  • Is it possible to remove the xlabels "d" and "e" without affecting the arrangement (in terms of spacing) of the bars? – JohnTortugo Aug 16 '14 at 00:12