Given an n-sample from some unknown density f on [0,1], it is easy to construct an
histogram of the data based on some given partition of [0,1], but not so much is known
about an optimal choice of the partition, especially when the data set is not large, even if
one restricts to partitions into intervals of equal length. Existing methods are either rules
of thumbs or based on asymptotic considerations and often involve some smoothness
properties of f. Our purpose in this paper is to give an automatic, easy to program and
efficient method to choose the number of bins of the partition from the data. It is based on bounds
on the risk of penalized maximum likelihood estimators due to Castellan and heavy simulations
which allowed us to optimize the form of the penalty function. These simulations show that the
method works quite well for sample sizes as small as 25.