2

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:

enter image description here

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:

enter image description here

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

4
  • Excuse me. But is it your histogram?
    – Sebastiano
    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
    – Sebastiano
    Apr 8 '20 at 20:05
  • 1
    @Sebastiano. Done
    – Mark
    Apr 8 '20 at 20:14
1

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}

enter image description here

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

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.