1

I am having problems with the datapoint placement when viewed in the graph. I tried to place it vertically by either using (anchor=west) but that didn't work either. The first values under USE(DAN) aren't even visible and it shows exponential values instead of (0.04). Any help would be really appreciated.

enter image description here

\begin{tikzpicture}
\begin{axis}[
    ybar,axis on top,
         title={Evidence retrieval time},
    enlargelimits=0.07,
            height=12cm, width=18cm,
        bar width=0.5cm,
        ymajorgrids, tick align=inside,
        enlarge y limits={value=.1,upper},
    legend style={at={(0.5,-0.10)},
      anchor=north,legend columns=3},
    ylabel={TIME(SECONDS)},
    symbolic x coords={USE (DAN),USE (Transformer),Infersent (fastText),Infersent (GloVe),BERT},
    xtick=data,
    yticklabel pos=left,
    nodes near coords ,
    nodes near coords align={vertical},
    ]
    \addplot [black!20!black, fill=blue!30] coordinates {(USE (DAN),0.02) (USE (Transformer),0.12)(Infersent (fastText),0.32) (Infersent (GloVe),0.32) (BERT,0.85)};
    
    
    \addplot [black!20!black, fill=red!30] coordinates {(USE (DAN),0.02) (USE (Transformer),0.25)(Infersent (fastText),0.61) (Infersent (GloVe),0.62) (BERT,1.90)};
    
    
    \addplot [black!20!black, fill=green!30] coordinates  {(USE (DAN),0.04) (USE (Transformer),0.48) (Infersent (fastText),0.98) (Infersent (GloVe),0.99)(BERT,3.56)};
    
\legend{Top-20,Top-50,Top-100}

\end{axis}
\end{tikzpicture}
0

You can change the node style of coordinate index 0 by

    coordinate style/.condition={
      {\coordindex==0}{
        yshift=2mm,
        font=\scriptsize,
        /pgf/number format/.cd,
        fixed,
        precision=2,
        /tikz/.cd}
    },

Complete code

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar,axis on top,
         title={Evidence retrieval time},
    enlargelimits=0.07,
            height=12cm, width=18cm,
        bar width=0.5cm,
        ymajorgrids, tick align=inside,
        enlarge y limits={value=.1,upper},
    legend style={at={(0.5,-0.10)},
      anchor=north,legend columns=3},
    ylabel={TIME(SECONDS)},
    symbolic x coords={USE (DAN),USE (Transformer),Infersent (fastText),Infersent (GloVe),BERT},
    xtick=data,
    yticklabel pos=left,
    nodes near coords ,
    nodes near coords align={vertical},
    coordinate style/.condition={
      {\coordindex==0}{
        yshift=2mm,
        font=\scriptsize,
        /pgf/number format/.cd,
        fixed,
        precision=2,
        /tikz/.cd}
    },
    ]
    \addplot [black!20!black, fill=blue!30] 
      coordinates {
        (USE (DAN),0.02)
        (USE (Transformer),0.12)
        (Infersent (fastText),0.32)
        (Infersent (GloVe),0.32) (BERT,0.85)};
    \addplot [black!20!black, fill=red!30]
      coordinates {
        (USE (DAN),0.02)
        (USE (Transformer),0.25)
        (Infersent (fastText),0.61)
        (Infersent (GloVe),0.62) (BERT,1.90)};
    \addplot [black!20!black, fill=green!30]
      coordinates {
        (USE (DAN),0.04)
        (USE (Transformer),0.48)
        (Infersent (fastText),0.98)
        (Infersent (GloVe),0.99)(BERT,3.56)};
\legend{Top-20,Top-50,Top-100}

\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

1

To get rid of the exponentials, add

    nodes near coords style={
       /pgf/number format/fixed, % set style to fixed number of decimals
       /pgf/number format/precision=2, % two decimals
       font=\footnotesize % smaller font to avoid overlap
       },

You should also add ymin=0, to set the lower yaxis limit.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    axis on top,
    title={Evidence retrieval time},
    enlargelimits=0.1, % <- modified
    height=12cm, width=16cm, % <- modified
    bar width=0.5cm,
    ymajorgrids, tick align=inside,
    enlarge y limits={value=.1,upper},
    legend style={at={(0.5,-0.10)},
    anchor=north,legend columns=3},
    ylabel={TIME(SECONDS)},
    symbolic x coords={USE (DAN),USE (Transformer),Infersent (fastText),Infersent (GloVe),BERT},
    xtick=data,
    yticklabel pos=left,
    nodes near coords ,
%    nodes near coords align={vertical}, % not needed
    nodes near coords style={
       /pgf/number format/fixed, % set style to fixed number of decimals
       /pgf/number format/precision=2, % two decimals
       font=\footnotesize % smaller font to avoid overlap
       },
    ymin=0, % added
    ]
    \addplot [black!20!black, fill=blue!30] coordinates {(USE (DAN),0.02) (USE (Transformer),0.12)(Infersent (fastText),0.32) (Infersent (GloVe),0.32) (BERT,0.85)};
    
    
    \addplot [black!20!black, fill=red!30] coordinates {(USE (DAN),0.02) (USE (Transformer),0.25)(Infersent (fastText),0.61) (Infersent (GloVe),0.62) (BERT,1.90)};
    
    
    \addplot [black!20!black, fill=green!30] coordinates  {(USE (DAN),0.04) (USE (Transformer),0.48) (Infersent (fastText),0.98) (Infersent (GloVe),0.99)(BERT,3.56)};
    
\legend{Top-20,Top-50,Top-100}

\end{axis}
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.