我试图重现以下图片:
但目前我可以:
有很多问题:
- 对数尺度不是对数的,即
256, 512, 1020, 2050
。我希望有256, 512, 1024, 2048
- y 轴和 x 轴与原始轴完全不同
x网格是多余的,见原图
\begin{tikzpicture} \begin{loglogaxis}[ /pgf/number format/.cd, use comma, 1000 sep={}, xmode=log, log basis x=2, log basis y=2, log ticks with fixed point, xlabel={Block size}, ylabel={Decoding latency, ns/op}, grid=major, legend entries={Critical, JNI, FOR, VInt}, legend pos=south east, xmin=128,xmax=16384, ymin=60,ymax=30000, ytick={120, 240, 480, 960, 1920, 3840, 7680, 15360}, xtick=data ] \addplot[red,very thick,mark=square*] coordinates { (128, 82.638) (256, 139.914) (512, 225.505) (1024, 396.605) (2048, 743.370) (4096, 1436.633) (8192, 2827.855) (16384, 5654.820) }; \addplot[green,very thick,mark=triangle*] coordinates { (128, 200.452) (256, 261.881) (512, 341.506) (1024, 518.709) (2048, 868.560) (4096, 1557.861) (8192, 2953.913) (16384, 5779.984) }; \addplot[blue,very thick,mark=diamond*] coordinates { (128, 194.441) (256, 346.855) (512, 592.312) (1024, 1100.371) (2048, 2089.506) (4096, 4204.929) (8192, 7758.365) (16384, 14938.887) }; \addplot[orange,very thick,mark=*] coordinates{ (128, 330.123) (256, 583.440) (512, 1046.636) (1024, 2149.478) (2048, 4058.115) (4096, 8023.846) (8192, 14458.539) (16384, 25235.819) }; \end{loglogaxis} \end{tikzpicture}
答案1
有点乏味,但经过大量调整后就相当接近了(阴影也是可能的,但请不要这样做。这只是一个 Excel 技巧,在我看来,对视觉没有任何帮助):
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{sansmath}
\sansmath
\pgfplotsset{compat=1.12}
\pgfplotstableread[col sep=comma]{
a,b,c,d,e
128, 82.638 ,200.452 ,194.441 ,330.123
256, 139.914 ,261.881 ,346.855 ,583.440
512, 225.505 ,341.506 ,592.312 ,1046.636
1024, 396.605 ,518.709 ,1100.371 ,2149.478
2048, 743.370 ,868.560 ,2089.506 ,4058.115
4096, 1436.633,1557.861,4204.929 ,8023.846
8192, 2827.855,2953.913,7758.365 ,14458.539
16384,5654.820,5779.984,14938.887,25235.819
}\mytable
\begin{document}\sffamily
\begin{tikzpicture}
\pgfkeys{/pgf/number format/.cd,use comma,1000 sep={},}
\begin{loglogaxis}[
log basis x=2,log basis y=2,
label style={font=\tiny},
xlabel={Block size},ylabel={Decoding latency, ns/op},
legend entries={Critical, JNI, FOR, VInt},
xmin=128,xmax=16384,
ymin=60,ymax=30720,
separate axis lines,
axis x line*=bottom,
axis y line*=left,
axis line style={draw=gray!50},
ytick={60,120,240,480,960,1920,3840,7680,15360,30720},
yticklabel={\pgfkeys{/pgf/fpu}\pgfmathparse{60*(2^(\ticknum))}%
\pgfmathprintnumber[fixed,precision=0]\pgfmathresult%
\pgfkeys{/pgf/fpu=false}%
},
xticklabel={\pgfkeys{/pgf/fpu}\pgfmathparse{2^(8+\ticknum)}%
\pgfmathprintnumber[fixed]\pgfmathresult%
\pgfkeys{/pgf/fpu=false}%
},
x tick label as interval,
ymajorgrids,
tick align=outside,
legend style={draw=none,fill=none,
at={(axis description cs:1.1,0.5)},
anchor=west,nodes={font=\tiny}},
tick label style={font=\tiny}
]
\addplot[red,very thick,mark=square*] table[x=a,y=b] {\mytable};
\addplot[green,very thick,mark=triangle*] table[x=a,y=c] {\mytable};
\addplot[blue,very thick,mark=diamond*] table[x=a,y=d] {\mytable};
\addplot[orange,very thick,mark=*] table[x=a,y=e] {\mytable};
\end{loglogaxis}
\end{tikzpicture}
\end{document}
答案2
您需要包。请pgfplots
注意使用xtick=\empty
、extra x ticks
、extra x tick labels
和extra y ticks
extra y tick labels
\documentclass{standalone}
\usepackage{tikz,pgfplots}
%\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[xtick=\empty,extra x ticks={256, 512, 1024, 2048,4096,8192,16384},extra x tick labels={256, 512, 1024, 2048,4096,8192,16384},ytick=\empty,extra y ticks={60,120,240,480,960,1920,3840,7680,15360,30720},extra y tick labels={60,120,240,480,960,1920,3840,7680,15360,30720},
/pgf/number format/.cd,
use comma,
1000 sep={},
xmode=log,
log basis x=2,
log basis y=2,
log ticks with fixed point,
xlabel={Block size},
ylabel={Decoding latency, ns/op},
grid=major,
legend entries={Critical, JNI, FOR, VInt},
legend pos=south east,
xmin=128,xmax=16400,
ymin=60,ymax=31000,
]
\addplot[red,very thick,mark=square*] coordinates {
(128, 82.638)
(256, 139.914)
(512, 225.505)
(1024, 396.605)
(2048, 743.370)
(4096, 1436.633)
(8192, 2827.855)
(16384, 5654.820)
};
\addplot[green,very thick,mark=triangle*] coordinates {
(128, 200.452)
(256, 261.881)
(512, 341.506)
(1024, 518.709)
(2048, 868.560)
(4096, 1557.861)
(8192, 2953.913)
(16384, 5779.984)
};
\addplot[blue,very thick,mark=diamond*] coordinates {
(128, 194.441)
(256, 346.855)
(512, 592.312)
(1024, 1100.371)
(2048, 2089.506)
(4096, 4204.929)
(8192, 7758.365)
(16384, 14938.887)
};
\addplot[orange,very thick,mark=*] coordinates{
(128, 330.123)
(256, 583.440)
(512, 1046.636)
(1024, 2149.478)
(2048, 4058.115)
(4096, 8023.846)
(8192, 14458.539)
(16384, 25235.819)
};
\end{loglogaxis}
\end{tikzpicture}
\end{document}
答案3
这是你想要的?
抱歉,我太忙了,没时间多评论,不过这是代码。我想你可以自己调整一下以满足你的需求。
请注意,您的观点似乎与原始图不对应(例如,红色原始曲线中的点(128,82.638)在哪里?
\documentclass{standalone}
\usepackage[frenchb]{babel}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[title=Random Dataset,height=10cm,width=12cm,
scaled ticks=false,
log ticks with fixed point,
enlargelimits={upper=0.3},
ymin=64,ymax=15360,xmin=64,xmax=16384,
log basis y =2,
xtickten={0,...,16},
log basis x =2,
ytick={60,120, 240, 480, 960, 1920, 3840, 7680, 15360},
yticklabels={60,120, 240, 480, 960, 1920, 3840, 7680, 15360},
xticklabels={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384},
xlabel={Block size},
ylabel={Decoding latency, ns/op},
ymajorgrids,
legend entries={Critical, JNI, FOR, VInt},
legend pos=south east,
xmin=128,xmax=16384,
ymin=60,ymax=16384,
ytick={120, 240, 480, 960, 1920, 3840, 7680, 15360},
]
\addplot[red,very thick,mark=square*] coordinates {
(128, 82.638)
(256, 139.914)
(512, 225.505)
(1024, 396.605)
(2048, 743.370)
(4096, 1436.633)
(8192, 2827.855)
(16384, 5654.820)
};
\addplot[green,very thick,mark=triangle*] coordinates {
(128, 200.452)
(256, 261.881)
(512, 341.506)
(1024, 518.709)
(2048, 868.560)
(4096, 1557.861)
(8192, 2953.913)
(16384, 5779.984)
};
\addplot[blue,very thick,mark=diamond*] coordinates {
(128, 194.441)
(256, 346.855)
(512, 592.312)
(1024, 1100.371)
(2048, 2089.506)
(4096, 4204.929)
(8192, 7758.365)
(16384, 14938.887)
};
\addplot[orange,very thick,mark=*] coordinates{
(128, 330.123)
(256, 583.440)
(512, 1046.636)
(1024, 2149.478)
(2048, 4058.115)
(4096, 8023.846)
(8192, 14458.539)
(16384, 25235.819)
};
\end{loglogaxis}
\end{tikzpicture}
\end{document}