# pgfplots with percentage on the axis

I am trying to draw a graph with percentage in x-axis and categories on y-axis. I cannot make the graph to show % sign. Here is my MWE:

\documentclass{article}
\usepackage{pgfplots}

\pagestyle{empty}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[
axis lines*=left,
title=Histogram of S\&P 500 CEOs Past Experience,
xbar,
width=8cm,
height=5cm,
xlabel={},
symbolic y coords={Sales, Marketing, Finance, Operations},
ytick=data,
xmin=0,
xmax=0.5,
nodes near coords,
nodes near coords align={horizontal}
]

[draw=blue,pattern=horizontal lines light blue]
coordinates
{(0.17,Sales)  (0.24,Marketing) (0.31,Finance) (0.42,Operations)};
\end{axis}
\end{tikzpicture}
\end{document}


as you can see, I can make the graph with decimal number and ideally I'd like to have % sign. Any suggestion?

-
Where do you want to show the % sign? After every x tick label? On the bar labels? Also, in your real application, are you only going to show four or five bars? In that case, you might want to get rid of the x axis, since all the needed information is already in the bar labels. –  Jake Dec 17 '12 at 22:23
@Jake: Yeah, I would like to show % sign after each label. I mean 17% instead of 0.17, 24% instead of 0.24 etc... –  N Nik Dec 17 '12 at 22:28

You can use point meta to perform the multiplication by 100 and

nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%}


\documentclass{article}
\usepackage{pgfplots}

\pagestyle{empty}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[
axis lines*=left,
title=Histogram of S\&P 500 CEOs Past Experience,
xbar,
width=8cm,
height=5cm,
xlabel={},
symbolic y coords={Sales, Marketing, Finance, Operations},
ytick=data,
xmin=0,
xmax=0.5,
point meta={x*100},
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%},
nodes near coords align={horizontal}
]
[draw=blue,pattern=horizontal lines light blue]
coordinates
{(0.17,Sales)  (0.24,Marketing) (0.31,Finance) (0.42,Operations)};
\end{axis}
\end{tikzpicture}

\end{document}


If you also want this formatting for the x tick labels, then you can use

xticklabel={\pgfmathparse{\tick*100}\pgfmathprintnumber{\pgfmathresult}\%},


(no need to explicitly give the labels):

\documentclass{article}
\usepackage{pgfplots}

\pagestyle{empty}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[
axis lines*=left,
title=Histogram of S\&P 500 CEOs Past Experience,
xbar,
width=8cm,
height=5cm,
xlabel={},
symbolic y coords={Sales, Marketing, Finance, Operations},
ytick=data,
xmin=0,
xmax=0.5,
xticklabel={\pgfmathparse{\tick*100}\pgfmathprintnumber{\pgfmathresult}\%},
point meta={x*100},
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%},
nodes near coords align={horizontal},
]
[draw=blue,pattern=horizontal lines light blue]
coordinates
{(0.17,Sales)  (0.24,Marketing) (0.31,Finance) (0.42,Operations)};
\end{axis}
\end{tikzpicture}

\end{document}


-

You can use xticklabel={\pgfmathprintnumber\tick\%}.:

\documentclass{article}
\usepackage{pgfplots}

\pagestyle{empty}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[
axis lines*=left,
title=Histogram of S \& P 500 CEOs Past Experience,
xbar,
width=8cm,
height=5cm,
xlabel={},
symbolic y coords={Sales, Marketing, Finance, Operations},
ytick=data,
xmin=0,
xmax=100,
nodes near coords,
nodes near coords align={horizontal},
xtick={20,40,60,80,100},
xticklabel=
{\pgfmathprintnumber\tick\%}
]