由于“FPGA”(棕色)图表的值非常小(0.0002,绿色不显示),我想改用对数刻度。我尝试使用“ymode=log”,但它使图表变得不稳定。
附加项不仅如此,我还想添加另一个右侧 y 轴来比较吞吐量数据,每个条形图的值范围为 0-2,可能是一条不连续的线图。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}\begin{figure}[!h]
\centering
\begin{tikzpicture}
\begin{axis}[
ybar,
ymin=0,
%enlargelimits=0.15,
legend image code/.code={%
\draw[#1, draw=none] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
},
legend style={at={(0.5,-0.10)},
anchor=north,legend columns=-1},
ylabel={Execution Time (ms)},
symbolic x coords={RGB2GRAY,Gaussian,Box,Sobel},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
]
\addplot coordinates {(RGB2GRAY,33) (Gaussian,54) (Box,127) (Sobel,246) };%CPU
\addplot [fill=teal!] coordinates {(RGB2GRAY,8.221) (Gaussian,13.3254) (Box,14.958) (Sobel,29.935) };%GPU
\addplot coordinates {(RGB2GRAY,20.234959834) (Gaussian,26.492609995) (Box,27.353843832) (Sobel,45.59262995) };%FPGA
\legend{CPU,GPU,FPGA}
\end{axis}
\end{tikzpicture}
\caption{Algorithms Excluding Image Read/Write}
\label{imageexclude}
\end{figure}
\end{document}
答案1
这不是一个完整的答案,因为结果并不漂亮。相反,这是为了告诉你它ymode=log
确实有效,至少在原则上是这样。结果看起来“不稳定”的原因是默认情况下log origin
设置为 1,因此一些条形悬在空中。更改此设置并将重复键放入样式中(我实际上不知道为什么ymode=log
不能成为样式的一部分,但这只是一个键)会产生
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\pgfplotsset{Freon axis/.style={ybar,
ymin=0.00001,ymax=10000,%<- added ymax
%enlargelimits=0.15,
legend image code/.code={%
\draw[#1, draw=none] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
},
legend style={at={(0.5,-0.10)},
anchor=north,legend columns=-1},
symbolic x coords={RGB2GRAY,Gaussian,Box, Sobel},
xtick=data,
nodes near coords,
nodes near coords style={anchor=east,rotate=-90,inner xsep=1pt},
log origin=infty
}}
\begin{axis}[Freon axis,ymode=log,ylabel={Execution Time (ms)}]
\addplot coordinates {(RGB2GRAY,54) (Gaussian,86) (Box,154) (Sobel,268) };%CPU
\addplot coordinates {(RGB2GRAY,170.71) (Gaussian, 172.065) (Box,193.72) (Sobel,215.38) };%GPU
\addplot coordinates {(RGB2GRAY,20.234959834) (Gaussian,26.492609995) (Box,27.353843832) (Sobel,45.59262995) };%FPGA
\legend{CPU,GPU,FPGA}
\end{axis}
\begin{axis}[Freon axis,ymode=log,axis y line=right,ytick=\empty,
ylabel={Throughput}]
\addplot [fill=green] coordinates {(RGB2GRAY,21) (Gaussian,32) (Box,27) (Sobel,40) };%CPU
\addplot [fill=green] coordinates {(RGB2GRAY,162.49) (Gaussian, 158.74) (Box,178.76) (Sobel,169.79) };%GPU
\addplot [fill=green] coordinates {(RGB2GRAY,0.0002) (Gaussian,0.0002) (Box,0.0002) (Sobel,0.0002) };%FPGA
\end{axis}
\end{tikzpicture}
\caption{Algorithms Including Image Read/Write.}
\end{figure}
\end{document}
这是对数的,但并不好看,因为现在棕色条变大了,而红色条变得太小了。可以安装用户转换,但我不确定这是否会为查看者提供您想要传达的信息。