我想绘制以下数据,我正在使用 CSV 文件和 pgfplotstable 包。
- (0,2.42130785530195E-02),
- (113.8,2.42130785530195E-02),
- (227.6,2.42130781357695E-02),
- (341.3,2.42130779271445E-02),
- (455.1,2.42130777185196E-02),
- (568.9,2.42130775098946E-02),
- (682.7,2.42130773012696E-02),
- (796.4,2.42130770926447E-02),
- (910.2,2.42130768840197E-02),
- (1024,2.42130766753947E-02),
我得到了这个情节
最小的工作环境:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\begin{document}
\pgfplotstableread[col sep = comma]{lossprob_jin1.csv}\loadedtable
\begin{figure*}
\centering
\begin{tikzpicture}
\begin{axis} [xlabel=Buffer-Size (bits),ylabel=Loss Probability (\%), legend entries = {H=0.6448}]
\addplot table [x=xsw, y=plp, col sep=comma] {\loadedtable} ;
\end{axis}
\end{tikzpicture}
\end{figure*}
\end{document}
答案1
这些差异太小,PGFPlots 无法处理。您可以通过从所有使用的数字中减去一个固定的量gnuplot
并“伪造”标签来解决这个问题:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
scaled y ticks=false,
y tick label style={
/pgf/number format/fixed,
/pgf/number format/precision=0
},
yticklabel=0.02421307\pgfmathprintnumber{\tick},
x tick label style={
/pgf/number format/1000 sep={}
},
xlabel=Buffer size in bits,
ylabel=Loss proabiblity in \%
]
\addplot[raw gnuplot, mark=*] gnuplot {
plot 'data.dat' using 2:($1-0.02421307)*1e10;
};
\end{axis}
\end{tikzpicture}
\end{document}
但老实说,您可能应该找到其他方法来显示缓冲区大小对丢失概率的影响(您确定这种影响是真实的或显著的吗?)
答案2
这是一个解决方法LuaTeX
\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.12}
\usepackage{siunitx}
\begin{document}
\pgfplotstableread
{
x y
0 2.42130785530195E-02
113.8 2.42130783443945E-02
227.6 2.42130781357695E-02
341.3 2.42130779271445E-02
455.1 2.42130777185196E-02
568.9 2.42130775098946E-02
682.7 2.42130773012696E-02
796.4 2.42130770926447E-02
910.2 2.42130768840197E-02
1024 2.42130766753947E-02
}\Bsizeloss
\begin{tikzpicture}
\begin{axis}[xlabel={Buffer-Size (bits)},
ylabel={Loss Probability, \% ($\times 10^{10}-242130700$)},
ytick={67,73,79,85},
legend entries = {H=0.6448},
grid = major
]
\addplot+ table[y expr=\directlua{tex.print(\thisrow{y}*1E10-242130700)},x=x] {\Bsizeloss};
\end{axis}
\end{tikzpicture}
答案3
你可以实现与AboAmmar 的回答也可以在 PDFLaTeX 中使用包xintexpr它可以处理任意位数的数字。
\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.12}
%\usepackage{siunitx}% seems not needed in this mwe
\usepackage{xintexpr}
\begin{document}
\pgfplotstableread
{
x y
0 2.42130785530195E-02
113.8 2.42130783443945E-02
227.6 2.42130781357695E-02
341.3 2.42130779271445E-02
455.1 2.42130777185196E-02
568.9 2.42130775098946E-02
682.7 2.42130773012696E-02
796.4 2.42130770926447E-02
910.2 2.42130768840197E-02
1024 2.42130766753947E-02
}\Bsizeloss
\begin{tikzpicture}
\begin{axis}[xlabel={Buffer-Size (bits)},
ylabel={Loss Probability, \% ($\times 10^{10}-242130700$)},
ytick={67,73,79,85},
legend entries = {H=0.6448},
grid = major
]
\addplot+ table[y expr=\xintthefloatexpr\thisrow{y}*1E10-242130700\relax,x=x] {\Bsizeloss};
\end{axis}
\end{tikzpicture}
\end{document}
PDFLaTeX 生成:
也许在更一般的情况下,需要用括号括住后面的表达式y expr
(特别是如果表达式使用带有逗号分隔参数的函数)。