histogram.tex 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. % Source: http://tex.stackexchange.com/a/65518/5645
  2. \documentclass{article}
  3. \usepackage[pdftex,active,tightpage]{preview}
  4. \setlength\PreviewBorder{2mm}
  5. \usepackage{pgfplots}
  6. \begin{document}
  7. \begin{preview}
  8. \begin{tikzpicture}
  9. \begin{axis}[/tikz/ybar, % -------- CF
  10. ybar legend, %-------- CF
  11. xtick align=outside,% -------- CF
  12. ymin=0,
  13. bar width=0.2cm,
  14. axis x line*=left,
  15. nodes near coords=\rotatebox{90}{\scriptsize\pgfmathprintnumber\pgfplotspointmeta},
  16. enlarge x limits=false,
  17. grid=major,
  18. height=7cm,
  19. title={All Results},
  20. xlabel={bias from reference in \%},
  21. ylabel={Number of Results},
  22. symbolic x coords={$<-20$,$-20$,$-19$,$-18$,$-17$,$-16$,$-15$,$-14$,$-13$,$-12$,$-11$,$-10$,$-9$,$-8$,$-7$,$-6$,$-5$,$-4$,$-3$,$-2$,$-1$,$0$,$1$,$2$,$3$,$4$,$5$,$6$,$7$,$8$,$9$,$10$,$11$,$12$,$13$,$14$,$15$,$16$,$17$,$18$,$19$,$20$,$>20$},
  23. xtick={$-20$,$-15$,$-10$,$-5$,$0$,$5$,$10$,$15$,$20$},
  24. minor x tick num=4, % ----------- CF
  25. extra x ticks={$<-20$,$>20$},% ----------- CF
  26. extra x tick style={xticklabel style={yshift=-15pt}},% ----------- CF
  27. %xticklabel style={inner sep=0pt, anchor=north east, rotate=45},% ----------- CF
  28. width=\textwidth]
  29. \addplot[red,fill=red!40!white] coordinates {($<-20$,3) ($-20$,2) ($20$,0) ($>20$,0)};
  30. \addplot[yellow,fill=yellow!40!white] coordinates {($-19$,1) ($-18$,2) ($-17$,0) ($-16$,1) ($-15$,0) ($15$,0) ($16$,0) ($17$,0) ($18$,0) ($19$,0)};
  31. \addplot[blue,fill=blue!40!white] coordinates {($-14$,0) ($-13$,1) ($-12$,1) ($-11$,0) ($-10$,1) ($10$,0) ($11$,1) ($12$,0) ($13$,0) ($14$,1)};
  32. \addplot[green,fill=green!40!white] coordinates {($-9$,1) ($-8$,5) ($-7$,14) ($-6$,46) ($-5$,105) ($-4$,185) ($-3$,126) ($-2$,297) ($-1$,276) ($0$,301) ($1$,250) ($2$,153) ($3$,67) ($4$,85) ($5$,37) ($6$,29) ($7$,9) ($8$,2) ($9$,10)};
  33. \legend{Bad,Fair,Good,Excellent}
  34. \end{axis}
  35. \end{tikzpicture}
  36. \end{preview}
  37. \end{document}