我想繪製以下數據,我使用 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
您可以實現與中相同的效果阿博阿馬爾的回答也在 PDFLaTeX 中,使用套件新泰普它可以處理任意位數的數字。
\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
(特別是如果表達式使用帶有逗號分隔參數的函數)。