调整较小且不相互重叠的节点标签

调整较小且不相互重叠的节点标签

是否可以使条形图上的数据标签变小并且不重叠?

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{siunitx}
\pgfplotsset{width=7cm,compat=1.3}
\hyphenation{}

\begin{document}
\begin{tikzpicture}
\begin{axis}[bar width=1pt,
    ybar,
    ymin=0,ymax=1700,
    %enlargelimits=0.15,
                legend image code/.code={%
                    \draw[#1, draw=none] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
                },  
    ymajorgrids = true,
    legend style={at={(0.5,-0.20)},
      anchor=north,legend columns=-1},
    ylabel={Execution Time (ms)},
    ymode=log,
    symbolic x coords={R2G,Gaus\\sian,Box,Sobel, Edge, Gsn\\Pyd, Ext\\Dtn, Orn\\Ast, Dsr\\Grn, Sft\\Ttl},
    xtick=data,
    nodes near coords,
    nodes near coords style={anchor=west,rotate=90,inner xsep=1pt},
    x tick label style={font=\tiny,align=center},
    ]
\addplot coordinates {(R2G,33) (Gaus\\sian,54)  (Box,85) (Sobel,132) (Edge, 145) (Gsn\\Pyd, 1118) (Ext\\Dtn, 133) (Orn\\Ast, 128) (Dsr\\Grn, 50) (Sft\\Ttl, 1620)};%CPU

\addplot [fill=teal!]  coordinates {(R2G,8.221) (Gaus\\sian,13.3254)  (Box,14.958) (Sobel,29.935) (Edge, 43) (Gsn\\Pyd, 3) (Ext\\Dtn, 2) (Orn\\Ast, 1) (Dsr\\Grn, 1) (Sft\\Ttl, 7)  };%GPU

\addplot coordinates {(R2G,20.234959834) (Gaus\\sian,26.492609995)  (Box,27.353843832) (Sobel,45.59262995) (Edge, 73.31923) (Gsn\\Pyd, 8)(Ext\\Dtn, 3) (Orn\\Ast, 4) (Dsr\\Grn, 5) (Sft\\Ttl, 20) };%FPGA

\addplot coordinates {(R2G,21.57) (Gaus\\sian,32.78)  (Box,36.45) (Sobel,49.23) (Edge, 78.35) (Gsn\\Pyd, 74) (Ext\\Dtn, 34) (Orn\\Ast, 28) (Dsr\\Grn, 17) (Sft\\Ttl, 153) };%HLS

\legend{CPU,GPU,FPGA,HLS}
\end{axis}
\end{tikzpicture}
\end{document}

答案1

一种方法是旋转刻度标签:

在此处输入图片描述

\documentclass{article}
\usepackage{pgfplots}
\usepackage{siunitx}
\pgfplotsset{width=7cm,compat=1.18}
\hyphenation{}

\begin{document}
\begin{tikzpicture}
\begin{axis}[x=6mm,
    ybar=1pt,
    bar width =3pt,
    ymin=0,ymax=2000,
    enlarge y limits={upper=0.15},
    legend image code/.code={\draw[#1, draw=none] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
                },
    ymajorgrids = true,
    legend style={at={(0.5,-0.3)},
                   anchor=north,legend columns=-1},
    ylabel={Execution Time (ms)},
    ymode=log,
    symbolic x coords={R2G,Gaussian,Box,Sobel, Edge, GsnPyd, ExtDtn, OrnAst, DsrGrn, SftTtl},
    xtick=data,
    nodes near coords,
    nodes near coords style={font=\tiny, anchor=west,rotate=90,inner xsep=0.5pt},
    x tick label style = {font=\small, rotate=45, anchor=east},
    ]
\addplot coordinates {(R2G,33) (Gaussian,54)  (Box,85) (Sobel,132) (Edge, 145) (GsnPyd, 1118) (ExtDtn, 133) (OrnAst, 128) (DsrGrn, 50) (SftTtl, 1620)};%CPU

\addplot [fill=teal!]  coordinates {(R2G,8.221) (Gaussian,13.3254)  (Box,14.958) (Sobel,29.935) (Edge, 43) (GsnPyd, 3) (ExtDtn, 2) (OrnAst, 1) (DsrGrn, 1) (SftTtl, 7)  };%GPU

\addplot coordinates {(R2G,20.234959834) (Gaussian,26.492609995)  (Box,27.353843832) (Sobel,45.59262995) (Edge, 73.31923) (GsnPyd, 8)(ExtDtn, 3) (OrnAst, 4) (DsrGrn, 5) (SftTtl, 20) };%FPGA

\addplot coordinates {(R2G,21.57) (Gaussian,32.78)  (Box,36.45) (Sobel,49.23) (Edge, 78.35) (GsnPyd, 74) (ExtDtn, 34) (OrnAst, 28) (DsrGrn, 17) (SftTtl, 153) };%HLS

\legend{CPU,GPU,FPGA,HLS}
\end{axis}
\end{tikzpicture}
\end{document}

相关内容