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.

I'm trying to display the tick labels of the y axis of just this graph within my document formatting to two decimal places. I've tried the following code but it seems that it doesn't like the way I'm trying to change the y tick label style, what have I done wrong?

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\pgfplotstableread{Pone.dat}{\Pone}
\begin{center}
\begin{tikzpicture}[scale=0.9]
\begin{axis}[minor tick num=1,xmin=0,xmax=6,ymin=100000, ytick={100000,125000,150000,175000,200000,225000,250000,275000,300000}, y tick label style={/pgf/number format/.cd,fixed,fixed zerofill,precision=2},
xlabel={X}, ylabel={Y},
\addplot [black,thick] table{\Pone};
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}

And just for example, Pone.dat is:

1 100000
2 150000
3 200000
4 210000
5 220000
6 230000
share|improve this question
    
Sorry, I've added the definition of \Pone and an example of the .dat file it is called from. –  Andy Mar 4 '12 at 11:39
add comment

1 Answer

up vote 12 down vote accepted

Some styles for the tick label placement and the inner sep are set after the user specified styles. If you use /pgf/number format/.cd in your style, this change of directory remains active, and TikZ complains about not finding keys like /pgf/number format/inner sep, which reside in the /tikz directory. You need to .cd back into the /tikz directory (or not use .cd, but use the full /pgf/number format path for all the options).

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

\begin{center}
\begin{tikzpicture}[scale=0.9]
\begin{axis}[
    minor tick num=1,
    xmin=0,
    xmax=6,
    ymin=100000,
    ytick={100000, 125000, 150000, 175000, 200000, 225000, 250000, 275000, 300000}, 
    xlabel={X}, ylabel={Y},
    y tick label style={
        /pgf/number format/.cd,
        fixed,
        fixed zerofill,
        precision=2,
        /tikz/.cd
    }
]
\addplot [black,thick] table [row sep=crcr]{
0 150000\\
2 200000\\
};
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}
share|improve this answer
    
Thanks Jake, that has worked great in my example. Out of interest is that the 'optimum' way for changing number of decimal places displayed? I found that half code example for changing the decimal places elsewhere, so it's not really obvious to me what the .cd and fixed do, it was only the precision=2 that seemed to suit my needs. –  Andy Mar 4 '12 at 12:22
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.