13

I recently learned about the log ticks with fixed point option in pgfplots, which I like very much. However, it seems like if I add it to the options of an axis like so

\begin{axis}[%
  max space between ticks=10pt,
  xmin=0.05,xmax=50, 
  ymin=0.0000001,ymax=1000000000,
  ymode=log,
  xmode=log,
  xscale=1.205,
  yscale=2.21,
  x tick label style={yshift=-0.5em,log ticks with fixed point},
  y tick label style={xshift=-0.2em},
  xlabel absolute,
  xlabel={$p\bar{p}/pp$ collisions -- $\sqrt{s}$ [TeV]},
  ylabel style={at={(ticklabel cs:0.5)},yshift=-2em},
  xlabel style={at={(ticklabel cs:0.5)},yshift=2em},
  ylabel={$\sigma$ [nb] or events/sec for $\mathcal{L} = 10^{33}\textrm{cm}^{-2}\textrm{s}^{-1}$}] 
\end{axis}

it always acts on both axis (x and y). Is there a way to only have it act on one axis (in this case: x axis?).

1 Answer 1

13

You can define new styles that format only one of the axes like so:

\pgfplotsset{
  log x ticks with fixed point/.style={
      xticklabel={
        \pgfkeys{/pgf/fpu=true}
        \pgfmathparse{exp(\tick)}%
        \pgfmathprintnumber[fixed relative, precision=3]{\pgfmathresult}
        \pgfkeys{/pgf/fpu=false}
      }
  },
  log y ticks with fixed point/.style={
      yticklabel={
        \pgfkeys{/pgf/fpu=true}
        \pgfmathparse{exp(\tick)}%
        \pgfmathprintnumber[fixed relative, precision=3]{\pgfmathresult}
        \pgfkeys{/pgf/fpu=false}
      }
  }
}

\documentclass{article}
\usepackage{pgfplots}

\pgfplotsset{
  log x ticks with fixed point/.style={
      xticklabel={
        \pgfkeys{/pgf/fpu=true}
        \pgfmathparse{exp(\tick)}%
        \pgfmathprintnumber[fixed relative, precision=3]{\pgfmathresult}
        \pgfkeys{/pgf/fpu=false}
      }
  },
  log y ticks with fixed point/.style={
      yticklabel={
        \pgfkeys{/pgf/fpu=true}
        \pgfmathparse{exp(\tick)}%
        \pgfmathprintnumber[fixed relative, precision=3]{\pgfmathresult}
        \pgfkeys{/pgf/fpu=false}
      }
  }
}


\begin{document}
\begin{tikzpicture}
\begin{axis}[%
  max space between ticks=10pt,
  xmin=0.05,xmax=50, 
  ymin=0.0000001,ymax=1000000000,
  ymode=log,
  xmode=log,
  log x ticks with fixed point,
  xscale=1.205,
  yscale=2.21,
] 
\end{axis}
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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