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.

As you can see, my plot currently has node labels with scale factors of both 10^6 and 10^5:

enter image description here

My goal is to specify a scale factor of 10^6 for every node label:

enter image description here

So my question is: How can I explicitly set the exponent in scientific number formatting?

\begin{tikzpicture}
\begin{axis}[
    width=6cm,
    xtick=\empty,
    ybar,
    ymin=0,
    ymax=3e6,
    bar width=1cm,
    scaled y ticks=base 10:-6,
    ymajorgrids,
    nodes near coords={\pgfmathprintnumber[sci,precision=1]{\pgfplotspointmeta}}
]
\addplot+[blue] coordinates {(0, 100 000)};
\addplot+[teal] coordinates {(0, 200 000)};
\addplot+[orange] coordinates {(0, 2 500 000)};
\end{axis}
\end{tikzpicture}
share|improve this question
2  
Welcome to TeX.SX. –  Claudio Fiandrino Jan 31 '13 at 10:24
add comment

1 Answer

up vote 5 down vote accepted

I'm not sure if you can get the PGF math parser to do this (might be a useful feature request), but you can use siunitx' \num macro, which has a fixed-exponent option:

enter image description here

\documentclass{report}
\usepackage{tikz} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{siunitx}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    width=6cm,
    xtick=\empty,
    ybar,
    ymin=0,
    ymax=3e6,
    bar width=1.4cm,
    scaled y ticks=base 10:-6,
    ymajorgrids,
    nodes near coords={
        \pgfmathfloattofixed{\pgfplotspointmeta} % Convert floating point to fixed point
        \num[
            scientific-notation = fixed,
            fixed-exponent = 6,
            round-mode = places,
            round-precision = 1,
            exponent-product=\cdot
        ]{\pgfmathresult}}
]
\addplot+[blue] coordinates {(0, 100 000)};
\addplot+[teal] coordinates {(0, 200 000)};
\addplot+[orange] coordinates {(0, 2 500 000)};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
works nicely, thanks! –  roediger Jan 31 '13 at 11:47
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.