22

How do I disable exponent notation on logarithmic scale?

I want ...,$10^0$,$10^1$,$10^2$,... replaced by ...,1,10,100,...

I have tried to play with this default(pgfplots manual p. 209):

\pgfplotsset{ log base 10 number format code/.code={$10^{\pgfmathprintnumber{#1}}$}
}

But I can't make it work, and it seems to be a complicated way to do a simple thing.


\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \pgfplotsset{log base 10 number format code/.code={$fun^{\pgfmathprintnumber{#1}}$}}  
  \begin{semilogxaxis}
    [xmin=1, xmax=1000, domain=1:1000]
    \addplot {ln(x)};
  \end{semilogxaxis}
\end{tikzpicture}
\end{document}

Just for fun

  • 3
    I will add this to the pgfplots todo list (the requests came up a couple of times now). It seems an easily usable predefined switch is adequate here. – Christian Feuersänger Dec 10 '11 at 21:04
  • @ChristianFeuersänger: Is log ticks with fixed point the easily usable switch you commented about? – Ben Voigt Oct 24 '14 at 22:08
  • @Ben Voigt: I believe that you are correct. Maybe log ticks with fixed point has been added to TikZ after my question!? Will you post an answer? – hpekristiansen Oct 25 '14 at 08:06
  • @BenVoigt Yes, it is. I suppose your request is motivated by http://tex.stackexchange.com/questions/208891/pgfplot-log-axis-more-than-one-tick-label-per-decade-1-2-5-10/208946#208946, right? Let us continue any comments/problem analysis on that link. – Christian Feuersänger Oct 25 '14 at 09:33
  • @Christian Feuersänger: Are you the helpful person, who added this feature? -If so, will you post a more contemporary answer to this question. /OP – hpekristiansen Oct 25 '14 at 15:25
  • @Hans-PeterE.Kristiansen: Christian is the helpful person, who made not only this feature, but all of pgfplots! Amazingly useful. – Ben Voigt Oct 25 '14 at 16:51

2 Answers2

17

In addition to the other answer, more recent versions of pgfplots come with the style log ticks with fixed point. It does almost the same: it reconfigures the number printer such that ticks are displayed in fixed point format. Its logic is somewhat more complicated to avoid rounding inaccuracies and different log bases.

Here is the result with this new feature:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
  \begin{semilogxaxis}[
    xmin=1,
    xmax=1000,
    domain=1:1000, 
    log ticks with fixed point,
    x tick label style={/pgf/number format/1000 sep=\,},
    ]
    \addplot {ln(x)};
  \end{semilogxaxis}
\end{tikzpicture}
\end{document}

enter image description here

12

Do you mean something like this:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \pgfplotsset{%
    x tick label style={/pgf/number format/1000 sep=\,},
    log base 10 number format code/.code={%
        $\pgfmathparse{10^(#1)}\pgfmathprintnumber{\pgfmathresult}$%
    }%
  }  
  \begin{semilogxaxis}
    [xmin=1, xmax=1000, domain=1:1000]
    \addplot {ln(x)};
  \end{semilogxaxis}
\end{tikzpicture}
\end{document}

enter image description here

Marco Daniel
  • 95,681
  • Yes thank you. Still a bit complicated, but I guess, I have to live with the fact, that there is no boolean to accomplice the task. – hpekristiansen Dec 10 '11 at 10:55
  • I sounds like you don't understand the code. Maybe I misunderstand your- – Marco Daniel Dec 10 '11 at 13:50
  • Your answer works hurray. I will accept your answer -> Though still hoping for a simpler solution, not involving extracting an exponent converting it into a number, and adding it back into the style. – hpekristiansen Dec 10 '11 at 13:55
  • Thanks for the code provided, worked most of the times for my purposes! However, I noticed, that your code does not correctly handle negative exponents, i.e. 10^(-0.3) leads to a label of "2" (==10^0.3) instead of "0.5". I worked around by changing your code to \pgfmathparse{1/10^(#1)} however, is there a general to avoid a wrong handling of the sign of #1 ? –  Jun 21 '13 at 09:47
  • Agreed, this answer does not work. I found a better but messy solution xticklabel={\pgfmathfloatparsenumber{\tick}\pgfmathfloatexp{\pgfmathresult}\pgfmathprintnumber{\pgfmathresult}} on http://pgfplots.sourceforge.net/gallery.html, which got used in my question and answer pgfplot log axis more than one tick label per decade (1,2,5,10) – Ben Voigt Oct 24 '14 at 21:41
  • To be clear, it's the \pgfmathparse{10^(#1)} that doesn't work, at least for me. The rest of the answer is helpful, because it shows the appropriate customization name. – Ben Voigt Oct 24 '14 at 22:06