# Drawing a histogram with boxes

I try to draw a histogram with boxes. Drawing histograms with pgfplots seems extremely simple, and I'm sure what I want to to isn't any more difficult, but I couldn't find a good example. Hence the question: How do I make a graphic like the one drawn here by hand? ## 1 Answer

You can draw it directly in tikz without pgfplot

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\newcommand\rectsep{3pt}
\newcommand\rectbox{%{x}{y}{dx}{dy}{Label}{color}
\draw[fill=#6] (#1cm+\rectsep,#2cm+\rectsep) rectangle node{#5} +(#3cm-2*\rectsep,#4cm-2*\rectsep);}
\draw[->](0,0)--(4,0)node[anchor=north west]{$V_1$};
\draw[->](0,0)--(0,4)node[anchor=south east]{$V_2$};
\foreach \Tick in {1,2,3}{
\draw (\Tick,0)-- +(0,-0.2) node[below]{$\Tick00$};
\draw[thin,gray] (\Tick,0)-- +(0,4);
\draw (0,\Tick)-- +(-0.2,0) node[left]{$\Tick00$};
\draw[thin,gray] (0,\Tick)-- +(4,0);
}
\begin{scope}
\clip (0,0) rectangle (4.7,4.7);
\rectbox{1}{1}{1}{2}{1}{red!40}
\rectbox{1}{3}{1}{2}{2}{blue!40}
\rectbox{2}{1}{1}{1}{3}{green!40}
\rectbox{2}{2}{1}{1}{4}{yellow!40}
\rectbox{2}{3}{1}{2}{5}{magenta!40}
\rectbox{3}{2}{2}{1}{6}{cyan!40}
\rectbox{3}{3}{2}{2}{7}{gray!40}
\end{scope}
\end{tikzpicture}
\end{document} 