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.

How can I force pgfplots to draw my axis ticks labels consistently? I mean instead of 0 a 0.0, instead of 1 a 1.0 in the below image.

enter image description here

EDIT: Code

\documentclass[a4paper,10pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}
\usepackage{siunitx}

\pgfplotsset{
compat=1.7,
every axis/.append style={
line width=1.25pt,
tick style={line width=1.25pt, color=black, line cap=round}
}
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  enlarge x limits=0.05,
  enlarge y limits=0.05,
  try min ticks=4,
  max space between ticks=50pt,
  y tick label style={
    /pgf/number format/.cd,
    fixed,
    fixed zerofill,
    precision=1
  },
  x tick label style={
    /pgf/number format/.cd,
    fixed,
    fixed zerofill,
    precision=2
  }
]
\addplot[red] table[x index=1,y index=7] {dataA.dat};
\end{axis}
\end{tikzpicture}

\end{document}

I can't attach the data file, so here's a link.

share|improve this question

1 Answer 1

up vote 17 down vote accepted

You can change the number format using the /pgf/number format keys (there are a lot of options). In this concrete case, you'll want to set fixed, fixed zerofill, precision=1 for the y axis, and precision=2 for the x axis:

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

\begin{tikzpicture}

\begin{axis}[
    y tick label style={
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=1,
        /tikz/.cd
    },
    x tick label style={
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=2,
        /tikz/.cd
    }
]
\addplot [domain=0.98:1.02] {rnd};
\end{axis} 
\end{tikzpicture}

\end{document}
share|improve this answer
    
I'll get an error. This is, I guess, due to the numbers are very small. They have the expansion 1e-19 or something. Is there a way to deal with that? –  DaPhil Feb 1 '13 at 16:17
    
@DaPhil: Sorry, I forgot to change the key directory back using /tikz/.cd (PGFPlots was still trying to apply normal tikz options using the /pgf/number format directory. I've edited my answer. –  Jake Feb 1 '13 at 16:40
    
Thanks a lot, now it works! –  DaPhil Feb 1 '13 at 16:53
1  
I took the liberty of adding a comma , after precision=2. –  Harish Kumar Feb 1 '13 at 23:51
1  
@strpeter: You need to change the directory key back using /tikz/.cd if you later want to apply other options to the labels that don't belong to the /pgf/number format directory (e.g. adding x tick label style=red later on). That's not the case in this code example, but resetting the directory to /tikz anyway can't hurt. –  Jake Jan 9 at 9:07

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.