3

Semilogarithmic plots normally mark major ticks with powers of 10 and no mantissa or separator, e.g., 10^3, 10^4,..., rather than 1.10^3, 1.10^4, etc. Pgfplots provides this capability through standard formats using default math fonts.

I need to use sans serif fonts for the tick numbers on both axes, which I've managed to do in the example below. Unfortunately, the ticks that I'd like to have in powers of ten appear with a mantissa and separator as well.

My question: How can I eliminate the mantissa and separator while keeping the other formatting as it is? I am running LuaLaTeX.

\documentclass{article}

\usepackage[svgnames,x11names]{xcolor} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\pgfplotsset{%
    width=0.9\textwidth,
    height=0.6\textwidth,
    every axis/.append style={thick},
    every minor tick/.append style={very thin,black}, 
    every major tick/.append style={thin, black}, 
    major tick length={1.2em}, 
    minor tick length={0.5em},
}

\begin{document}

\begin{tikzpicture}
\begin{semilogyaxis}[
     log basis y=10, 
     minor x tick num=1, 
     xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
     yticklabel={$\pgfmathparse{10.00^(\tick)}\mathsf{\pgfmathprintnumber[std=-2:2, precision=1]{\pgfmathresult}}$},
     % does not solve the problem of wanting an 10^\tick with no mantissa.  
]
    \addplot [domain=0:10, ultra thick, color=blue] {exp(x)};
\end{semilogyaxis}
\end{tikzpicture}

\end{document}

enter image description here

The plot below, obtained by commenting out the yticklabel entry in the code, shows the default semilog layout with no mantissa. (For clarity, my question is not about adjusting the lower values (1, 10, 100) or resetting logarithmic ordinate to fixed point numbers, which can be done by resetting std=.)

enter image description here

1 Answer 1

6

If I understand correctly, you care about \mathsf, but not about the fixed point numbers.

In this case, you can modify the way pgfplots typesets the math labels. To this end, pgfplots offers the style log number format basis which has the default value

/pgfplots/log number format basis/.code 2 args={$#1^{\pgfmathprintnumber{#2}}$},

Your use-case can be addressed as follows:

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\pgfplotsset{%
    width=0.9\textwidth,
    height=0.6\textwidth,
    every axis/.append style={thick},
    every minor tick/.append style={very thin,black}, 
    every major tick/.append style={thin, black}, 
    major tick length={1.2em}, 
    minor tick length={0.5em},
}

\begin{document}

\begin{tikzpicture}
\begin{semilogyaxis}[
     log basis y=10, 
     minor x tick num=1, 
     xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
     log number format basis/.code 2 args={$\mathsf{#1^{\pgfmathprintnumber{#2}}}$},
]
    \addplot [domain=0:10, ultra thick, color=blue] {exp(x)};
\end{semilogyaxis}
\end{tikzpicture}

\end{document}

enter image description here

5
  • Thank you! This produces the needed formatting of the 10^x labels. Is it also possible to retain the behavior associated with sep=-2:2 while formatting the log numbers in this manner?
    – John
    Nov 14, 2017 at 23:19
  • Do you want to control where to place tick labels? What is sep=-2:2? Maybe this is a good new question since others might see and and benefit from it -- more as if we answer it here in the comments. Nov 15, 2017 at 19:22
  • Opps! I meant "std=-2:2" as in the original code: \pgfmathprintnumber[std=-2:2, precision=1] ... the option to use fixed point at small exponents and powers of ten for larger absolute values of exponents.
    – John
    Nov 16, 2017 at 1:43
  • Ah - makes sense. I suppose you got add code if sorts "if #2 < 2then use code which makes use of std=-2:2 else use the standard log formatting code". This might be of interest to others as well -- please post a separate question like "How can I customize number formatting styles for log plots based on the numbers?" Nov 19, 2017 at 17:30
  • Ok, this is now posted here.
    – John
    Nov 21, 2017 at 16:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .