1

The nodes (data labels) are being covered up by the error bars. I tried fixing this with:

every node near coord/.append style={rotate=90,xshift=+0.7cm,yshift=-0cm}

But, when I did this, the other nodes have completely shifted (too high up). How do I apply different positioning of nodes in this case where I am unable to define the code below for each coordinate without changing the color and special grouping of the bars?

    \addplot+[error bars/.cd,
            y dir=both,y explicit,
            error mark=line*,error bar style={color=mapped color},
            error mark options={line width=1pt,mark size=4pt},
            nodes near coords,
nodes near coords=\raisebox{1cm}{\pgfmathprintnumber\pgfplotspointmeta}
]

Dinosaurs Example

  \documentclass[border=2pt]{standalone} 
\usepackage{pgfplotstable}
\usepackage{pgfplots,filecontents}
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}


\title{dinosaurs}


\begin{document}
\begin{tikzpicture}
\pgfplotsset{every node/.append style={font=\tiny}}
\pgfplotsset{every tick label/.append style={font=\tiny}}
\begin{axis}[
    title={dinos},
    ybar=5pt,
    ymin=1e5
    enlargelimits=0.15,
    legend style={at={(0.5,-0.15)},anchor=north,legend columns=-1},
    ylabel={Mean Dinosaurs},
    symbolic x coords={t-rex,velociraptor,brachiosaurus,pterodactyl},
    xtick=data,
    nodes near coords,
    nodes near coords align={center},style={font=\tiny},
    point meta=y *10^-7
    ]
\addplot+[error bars/.cd,
    y dir=both,y explicit,
    error mark=line*,error bar style={color=mapped color},
    error mark options={line width=1pt,mark size=4pt}
    ]
coordinates {
    (t-rex,1.01e7)  +- (1e5,1e5) 
    (velociraptor,2.02e6)     +- (1e6,1e6)
    (brachiosaurus,2.01e7)    +- (4e6,4e6)
    (pterodactyl,3.29e6)    +- (1e5,1e5)};


\addplot+[error bars/.cd,
    y dir=both,y explicit,
    error mark=line*,error bar style={color=mapped color},
    error mark options={line width=1pt,mark size=4pt},

    ]
    %nodes near coords=\raisebox{1cm}{\pgfmathprintnumber\pgfplotspointmeta}]
coordinates {
    (t-rex,2.02e6)     +- (1e6,1e6)
    (velociraptor,1.01e7)  +- (1e5,1e5) 
    (brachiosaurus,3.29e6)    +- (1e5,1e5)
    (pterodactyl,2.01e7)    +- (4e6,4e6)};

\legend{Estimated,Actual}

\end{axis}
\end{tikzpicture}
\end{document}
  • Welcome to TeX-SE! Unfortunately, your code does not compile. This has several reasons, one of them is that there is a comma missing after ymin=1e5, and then you use error bars/.cd, but add keys afterwards that do not belong there. Could you please make your code compilable? – user121799 Apr 5 at 15:40
  • Okay, hopefully, it compiles now. I am using overleaf – katelyn Apr 5 at 15:51
  • Nope.` every node near coord/.append` is not a valid key, especially when used after error bars/.cd,. – user121799 Apr 5 at 15:53
  • Missed some! Edited it again. – katelyn Apr 5 at 16:18
1

Here is a code that compiles and fixes the issue with

every node near coord/.append style={rotate=90,anchor=south west,
    inner ysep=0.5pt}

Code:

\documentclass[border=2pt]{standalone} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.16} 

\title{dinosaurs}


\begin{document}
\begin{tikzpicture}
\pgfplotsset{every node/.append style={font=\tiny}}
\pgfplotsset{every tick label/.append style={font=\tiny}}
\begin{axis}[
    title={dinos},
    ybar=5pt,
    ymin=1e5,
    enlargelimits=0.15,
    legend style={at={(0.5,-0.15)},anchor=north,legend columns=-1},
    ylabel={Mean Dinosaurs},
    symbolic x coords={t-rex,velociraptor,brachiosaurus,pterodactyl},
    xtick=data,
    nodes near coords,
    nodes near coords align={center},style={font=\tiny},
    point meta={y*10^-7},
    every node near coord/.append style={rotate=90,anchor=south west,
    inner ysep=0.5pt}
    ]
\addplot+[error bars/.cd,
    y dir=both,y explicit,
    error mark=line*,error bar style={color=mapped color},
    error mark options={line width=1pt,mark size=4pt}
    ]
coordinates {
    (t-rex,1.01e7)  +- (1e5,1e5) 
    (velociraptor,2.02e6)     +- (1e6,1e6)
    (brachiosaurus,2.01e7)    +- (4e6,4e6)
    (pterodactyl,3.29e6)    +- (1e5,1e5)};


\addplot+[error bars/.cd,
    y dir=both,y explicit,
    error mark=line*,error bar style={color=mapped color},
    error mark options={line width=1pt,mark size=4pt},
    ]
    %nodes near coords=\raisebox{1cm}{\pgfmathprintnumber\pgfplotspointmeta}]
coordinates {
    (t-rex,2.02e6)     +- (1e6,1e6)
    (velociraptor,1.01e7)  +- (1e5,1e5) 
    (brachiosaurus,3.29e6)    +- (1e5,1e5)
    (pterodactyl,2.01e7)    +- (4e6,4e6)};

\legend{Estimated,Actual}

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

enter image description here

  • Thank you so much :) Is there any way I can center the node for {t-rex,1.01e7} and not the other bars? – katelyn Apr 5 at 16:45
  • @katelyn Yes. But this is not how this site works, sorry. You ask a question and get an answer to the original question. If you then change the question, this is too cumbersome for me to deal with. If you think this answer answers the original question, please consider accepting it and using it as a basis for a new question. – user121799 Apr 5 at 17:09
  • 1
    great suggestion! it's accepted as the answer! – katelyn Apr 5 at 17:19

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.