Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When using tikzpicture in the pgfplots package, how can I change use PERCENTAGE for xticklabel or yticklabel.

Here is a simple example:

\documentclass[a4paper]{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xlabel=Cost,
        ylabel=Rate]
    \addplot[color=red,mark=x] coordinates {
        (2,0.003)
        (3,0.004)
        (4,0.005)
};
    \end{axis}
\end{tikzpicture}
\end{document}

How can I change the yticklabel to percentage style: i.e. 0.3%, 0.4%, 0.5%, etc.

I checked the documentation pdfplots.pdf and pdfplotstable.pdf. There are many Number Printing Settings available but I couldn't find anything that can covert the numbers to percentage style.

Thanks to all for your help! This is what I have right now. It still has problems.

\documentclass[a4paper]{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xlabel=Cost,
        ylabel=Rate,
        scaled ticks=false,
        yticklabel=\pgfmathprintnumber{\tick}\,\%,
        yticklabel style={/pgf/number format/.cd,fixed,precision=3}]
    \addplot[color=red,mark=x] coordinates {
        (2,0.003)
        (3,0.004)
        (4,0.005)
};
    \end{axis}
\end{tikzpicture}
\end{document}
share|improve this question
4  
I think this is a duplicate of this one tex.stackexchange.com/questions/58566/pgfplots-in-ticks-labels Is that right? –  percusse May 1 '13 at 15:36
    
Welcome to TeX.sx! –  Peter Jansson May 1 '13 at 15:50
    
One more problem: The other question works well for number like 3%, 4%, 5%, etc, not for 0.3%, 0.4%, 0.5%. It just shows 3% 4% 5% and on top of the graph it has 10^(-3) –  Titanic May 1 '13 at 19:29
    
the relevant keys are given in for example tex.stackexchange.com/questions/35909/… –  percusse May 1 '13 at 22:11
    
Yes. I tried that before, it works well for numbers with many decimals, but it doesn't work when combined with xticklabel=\pgfmathprintnumber{\tick}\,\% I updated my post with what I have right now. –  Titanic May 2 '13 at 13:51
show 1 more comment

1 Answer

A collection of comments

\documentclass[a4paper]{article}
\usepackage{pgfplots}
\begin{tikzpicture}
    \begin{axis}[
        xlabel=Cost,
        ylabel=Rate,
        scaled ticks=false,
        yticklabel=\pgfmathparse{100*\tick}\pgfmathprintnumber{\pgfmathresult}\,\%,
        yticklabel style={/pgf/number format/.cd,fixed,precision=2}]
    \addplot[color=red,mark=x] coordinates {
        (2,0.003)
        (3,0.004)
        (4,0.005)
};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.