Improved bin count optimization for histograms.
Fix histograms sometimes plotting out of bounds.