Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to put a number above only one of the bars in the bar chart. For example, above the bar A, I want to put a number say 200. Other bars will not have any number at the top. This is my code.

\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
legend style={at={(0.5,-0.2)},
anchor=north,legend columns=-1},
title={Data=30\%},
ylabel={Values},
grid=major,
symbolic x coords={A,B,C,D},
xtick=data,
ytick={6600,6650,6700,6750,6800,6850,6900,6950},
ylabel style={font=\Large},
% nodes near coords,
% nodes near coords align={vertical},
x tick label style={rotate=45,anchor=east},
]
\addplot [MyLineStyle,draw=black,error bars/.cd,y dir=both,y explicit,error bar style={line width=1pt}] coordinates
{
(A,6898.965904)+-(20,20)
(B,6801.9847)+-(20,20)
(C,6734.0923)+-(10,10)
(D,6698.2353)+-(10,10)
};
\end{axis}
\end{tikzpicture}

I want to place a number 200 just above the bar A and leave B, C, D as they are.

share|improve this question
    
Welcome to TeX.SX. –  Claudio Fiandrino Feb 16 '13 at 8:17
    
If the answer solved your problem, please consider to accept it. I would courteously suggest you for the future to upvote all answers you find useful, including those to others' questions and to check/accept the best answers to your own questions by clicking the green tick on the left-hand side of the answer. This will help the community. –  Claudio Fiandrino Feb 26 '13 at 10:44

1 Answer 1

In pgfplots you can always access the coordinates of the plot by means of axis cs; in this case, for example, you want to place a label with a number above (axis cs:A,6898.965904) plus the value of the error bar (this is something required otherwise your label will be located inside the error bar).

To place a label it is possible to exploit the usual TikZ syntax:

\node[options] at (location) {label};

thus:

\node[above] at (axis cs:A,6898.965904) {200};

but we should consider also the error bar. I suggest the use of the calc library in such a way:

\node[above] at ($(axis cs:A,6898.965904)+(0,20)$) {200};

This means that the label will be located above a position that comprises the height of the error bar.

A complete MWE:

\documentclass{article}

\usepackage{pgfplots}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
legend style={at={(0.5,-0.2)},
anchor=north,legend columns=-1},
title={Data=30\%},
ylabel={Values},
grid=major,
symbolic x coords={A,B,C,D},
xtick=data,
ytick={6600,6650,6700,6750,6800,6850,6900,6950},
ylabel style={font=\Large},
% nodes near coords,
% nodes near coords align={vertical},
x tick label style={rotate=45,anchor=east},
]
\addplot [draw=black,error bars/.cd,y dir=both,y explicit,error bar style={line width=1pt}] coordinates
{
(A,6898.965904)+-(20,20)
(B,6801.9847)+-(20,20)
(C,6734.0923)+-(10,10)
(D,6698.2353)+-(10,10)
};
\node[above] at ($(axis cs:A,6898.965904)+(0,20)$) {200};
\end{axis}
\end{tikzpicture}

\end{document}

The result:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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