11

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

1 Answer 1

13

A collection of comments

\documentclass[a4paper]{article}
\usepackage{pgfplots}
\begin{document}
\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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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