Consider the following plot (MWE below):
I have some questions.
- [solved] Why is there an extra
1after the interval[10,11)? - [see edit below] How to make the last interval to be closed? I mean, I'd like to have
[9,10]with value4(I just put[10,11)to count the last occurrence). - [solved] If possible, I'd like to write the values exactly over the bars, I mean, aligned at the centre (move a little bit to right).
I tried to find some similar solution but no progress.
MWE
\documentclass[border=1pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepgfplotslibrary{statistics}
\pgfplotsset{%
compat = 1.12, % I am not sure
major grid style = {color = blue!80, line width = .6pt},
every axis title/.append style = {font = \bfseries},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Title Here},
ybar interval,
height = 6cm,
width = 18cm,
xmajorgrids = false,
ymajorgrids = true,
major tick length = 0pt,
minor tick length = 0pt,
xticklabel={%
$ [ \pgfmathprintnumber\tick , \pgfmathprintnumber\nexttick ) $%
},
axis y line = left,
axis x line = bottom,
every outer y axis line/.append style = {-},
every outer x axis line/.append style = {-},
xlabel = {faa},
xlabel style = {at = {(.5,-.2)}, anchor = north},% I'd like bold also
ylabel = {foo},
every node near coord/.append style = {%
anchor = south west,
black,
% I'd like bold/italic
},
nodes near coords,
ymin = 0, ymax = 9,
xmin = 0, xmax = 11.5,
]
%%
\addplot+[%
hist={% bins = 9, data max = 10 destroy everything
bins = 10,
data min = 1,
data max = 11,
},
fill = cyan!50,
]
table[row sep=\\, y index=0]{%
data\\%
1\\%
2\\2\\%
3\\3\\3\\%
4\\4\\%
5\\5\\5\\5\\5\\5\\5\\5\\%
6\\6\\6\\6\\6\\6\\%
7\\7\\7\\7\\%
8\\8\\8\\%
9\\9\\9\\
10\\%
};
\end{axis}
\end{tikzpicture}
\end{document}
Edit: for 2. I did this trick not so pretty but it fitted like a glove.
\node[fill=white,anchor=north,inner sep=1pt] at (11.05,-2pt) {$[9,10]$};


