12

I would like to have y tick labels like 1, 10, 10^2, 10^3, ...

So far I found found to display them either 1, 10, 100, 1000, ... or with exponents.

Is this possible with pgfplots?

user24520
  • 287
  • 2
    It's probably most practical to do it by hand: ytickten={0,...,4}, yticklabels={1, 10, $10^2$, $10^3$, $10^4$} – Jake Jan 17 '13 at 15:05
  • Welcome to TeX.sx! There are a number of options in this direction described in section 4.12 of the pgfplots manual. – Andrew Swann Jan 17 '13 at 15:11
  • Welcome to TeX.SX. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. – Claudio Fiandrino Jan 17 '13 at 15:12

1 Answers1

6

Yeah, /pgf/number format/std does not work.

For log axes the normal \pgfmathprintnumber macro is not used. Instead, by default $<base>^{\pgfmathprintnumber{<exponent>}}$ is used. (See pgfplots manual, section 4.12.2 “PGFPlots-specific Number Formatting”, pp. 227f.)

The code below overwrites this code key stored in log number format basis with a few conditionals. There are certainly different ways to build this conditional.

If we would want to use \ifcase for the exponent (#2) we should \pgfmathtruncatemacro it first, but for these three cases, this suffices.

Note that for negative exponents the <base>^<exponent> is used again: 10–1, 10–2, …

Code

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{
    log number format basis/.code 2 args={{%
    $
        \ifdim#2pt=0.0pt\relax
            1
        \else\ifdim#2pt=1.0pt\relax
                #1
            \else
                #1^{\pgfmathprintnumber{#2}}
            \fi
        \fi
        $%
    }},
}
\begin{document}
\begin{tikzpicture}
    \begin{semilogyaxis}[domain=0:10]
    \addplot {exp(x)};
    \end{semilogyaxis}
\end{tikzpicture}
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821