我最近了解了log ticks with fixed point
pgfplots 中的选项,我非常喜欢它。但是,如果我将它添加到轴的选项中,就像这样
\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}
它总是作用于两个轴(x 和 y)。有没有办法让它只作用于一个轴(在本例中是 x 轴?)。
答案1
您可以定义仅格式化其中一个轴的新样式,如下所示:
\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}