我想在图表中添加一些额外的刻度。但是,它们似乎在格式化数字方面存在问题。
\documentclass{article}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[
grid=major,
xmax=1,
xmin=1e-1,
extra x ticks={0.5},
extra x tick style={log identify minor tick positions=true}
]
\addplot {rnd};
\end{loglogaxis}
\end{tikzpicture}
\end{document}
这将得到以下结果:
额外的刻度被放置在正确的位置,但它们的标签完全错误。如果插入“0.5”而不是“5e-1”,则会产生相同的结果。
额外的:
当我省略“extra tick”代码并使用“xticks = data”时,
\pgfplotsset{tick style=log identify minor tick positions=true}
在绘图代码之前,这会产生相同的错误结果。“额外 x 刻度”很有用,因为它们打印得比主刻度小。
已编辑:代码已清理,现在仅显示错误的代码。
答案1
这看起来像是一个错误。作为一种解决方法,您可以设置
extra x tick style={
xticklabel={
\pgfmathparse{exp(\tick)}
\pgfmathprintnumber[sci, precision=1]{\pgfmathresult}
}
}
打印正确的标签:
\documentclass[11pt,titlepage,a4paper]{article}
\usepackage{tikz,pgfplots,pgfplotstable}
\usetikzlibrary{shapes,arrows,trees,positioning}
%\pgfplotsset{tick style=log identify minor tick positions=true}
% read data
\pgfplotstableset{
col sep=comma
}
\pgfplotstableread{P,Empiric,Analytic,PT
1,1,1,1
0.5,0.9998,0.999755859375,0.0625
0.2,0.7233,0.703468589015119,0.0016
0.1,0.207,0.192731013518619,0.0001
0.05,0.03,0.0258145058547874,6.25e-06
0.02,0.0016,0.0010448397034175,1.6e-07
0.01,0.0002,7.60525098816179e-05,1e-08
}\simulation
%plot
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[
grid=major,
x post scale = 1.5,
xlabel= {channel bit error probability p},
ylabel= {probability of decoding error},
every axis y label/.style={at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel},
every axis x label/.style={at={(ticklabel cs:0.5)},anchor=near ticklabel},
xmax=1,
xmin=1e-2,
legend pos = south east,
%xtick =data,
xtick = {1e0,1e-1,1e-2},
extra x ticks={2e-2,5e-2,2e-1,5e-1},
extra x tick style={log identify minor tick positions=true,font=\footnotesize,
xticklabel={
\pgfmathparse{exp(\tick)}
\pgfmathprintnumber[sci, precision=1]{\pgfmathresult}
}}
]
\addplot table[domain=1e-2:1e0,x=P,y=Empiric] {\simulation};
\addplot table[domain=1e-2:1e0,x=P,y=Analytic] {\simulation};
\addplot [dashed] table[domain=1e-2:1e0,x=P,y=PT] {\simulation};
\legend{$empirisch$,$analytisch$,$p^{t+1}$}
\end{loglogaxis}
\end{tikzpicture}
\end{document}
答案2
pgfplots
这是:如果 x 在 [0.1,1] 中则失败的一个错误log identify minor tick positions=true
。我已经在开发版本中修复了它;将成为下一个稳定版本的一部分。