# Insert indications on the histogram bars with tikz

I would like to insert some indications on the histogram bars. The only thing I've done so far is to add some labels. But the desired result looks more like the following figure:

My code:

\documentclass{article}
\usepackage{tikz,pgf,pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
legend style={at={(0.5,-0.2)},
anchor=north,legend columns=-1},
ylabel={No. of edges},
xlabel={weights},
xtick=data,
nodes near coords,
nodes near coords align={vertical}
]
\addplot[fill=white, draw=black] coordinates {(1,22084) (2,4627) (3,742)
(4,377) (5,199) (6,93) (7,55) (8,44)};
\end{axis}
\end{tikzpicture}
\end{document}


produces the picture:

I would like to indicate the first and the second bar of this picture.

• Excuse me. But is it your histogram? Apr 8 '20 at 19:54
• @Sebastiano. Iedited my post
– Mark
Apr 8 '20 at 20:04
• Put, please, also the \documentclass and the packages: a MWE complete. +1 Apr 8 '20 at 20:05
• @Sebastiano. Done
– Mark
Apr 8 '20 at 20:14

You can use name nodes near coords to get

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\pgfplotsset{% https://tex.stackexchange.com/a/75811/121799
name nodes near coords/.style={nodes near coords={},
every node near coord/.append style={anchor=center,coordinate,
name=#1-\coordindex,
alias=#1-last,
},
},
name nodes near coords/.default=coordnode
}

\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
legend style={at={(0.5,-0.2)},
anchor=north,legend columns=-1},
ylabel={No. of edges},
xlabel={weights},
xtick=data,
nodes near coords,
nodes near coords align={vertical}
]
\addplot[fill=white, draw=black,name nodes near coords] coordinates {(1,22084) (2,4627) (3,742)
(4,377) (5,199) (6,93) (7,55) (8,44)};
\end{axis}
\draw[latex-]  (coordnode-0) -- ++ (-2,2) node[above left]{first distribution};
\draw[latex-]  (coordnode-1) -- ++ (2,2) node[above right]{second distribution};
\end{tikzpicture}
\end{document}


I exaggerated the lengths of the arrows, but you can change these coordinates to whatever you find appropriate.