条形图中的停止值相互重叠

条形图中的停止值相互重叠

我怎样才能避免值相互重叠以及与前面的条重叠?

\begin{figure}[!h]
\centering
\begin{tikzpicture}
\begin{axis}[
    ybar,
    ymin=0,ymax=300,%<- 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},
    ylabel={Execution Time (ms)},
    symbolic x coords={RGB2GRAY,Gaussian,Box, Sobel},
    xtick=data,
    nodes near coords,
    nodes near coords align={vertical},
    ]
\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}[
    ybar,
    ymin=0,ymax=300,%<- 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},
    ylabel={Execution Time (ms)},
    symbolic x coords={RGB2GRAY,Gaussian,Box, Sobel},
    xtick=data,
    nodes near coords,
    nodes near coords align={vertical},
    ]
\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,) (Gaussian,)  (Box,) (Sobel,) };%FPGA
\end{axis}



\end{tikzpicture}
\caption{Algorithms Including Image Read/Write }
\end{figure}

答案1

另一种粗略的方法:旋转节点并改变两个axis环境之间的锚点。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\begin{axis}[
    ybar,
    ymin=0,ymax=300,%<- 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},
    ylabel={Execution Time (ms)},
    symbolic x coords={RGB2GRAY,Gaussian,Box, Sobel},
    xtick=data,
    nodes near coords,
    nodes near coords style={anchor=east,rotate=-90,inner xsep=1pt}
    ]
\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}[
    ybar,
    ymin=0,ymax=300,%<- 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},
    ylabel={Execution Time (ms)},
    symbolic x coords={RGB2GRAY,Gaussian,Box, Sobel},
    xtick=data,
    nodes near coords,
    nodes near coords style={anchor=west,rotate=-90,inner xsep=1pt}
    ]
\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,) (Gaussian,)  (Box,) (Sobel,) };%FPGA
\end{axis}
\end{tikzpicture}
\caption{Algorithms Including Image Read/Write.}
\end{figure}
\end{document}

在此处输入图片描述

将来,我希望您发布以 开头\documentclass、以 结尾\end{document}且可以编译的最小但完整的代码。正如在这个答案中所说,很多事情都取决于文档的设置。

相关内容