4
$\begingroup$

Suppose I have some dataset,e.g.,

Histogram[RandomVariate[PoissonDistribution[2], 10000], 10]

which gives,

$\hspace{2cm}$enter image description here

How can I change the histogram such that it has variable bin size such, e.g., the first six bins have size 1 while the last two have size 2?

$\endgroup$
0

2 Answers 2

6
$\begingroup$

From the documentation of Histogram:

Histogram[{Subscript[x, 1],Subscript[x, 2],[Ellipsis]},bspec,hspec]

bspec: {{b1,b2,b3...}} use the bins [b1,b2),[b2,b3),...

Therefore,

Histogram[
 RandomVariate[PoissonDistribution[3], 
  10000], {{1, 2, 3, 4, 6, 8, 10, 12}}]

Mathematica graphics

$\endgroup$
2
  • 1
    $\begingroup$ Just what I was looking for. I'm not sure how I missed this. Thanks! $\endgroup$
    – JeffDror
    Commented Sep 12, 2014 at 13:53
  • $\begingroup$ I guess the lesson is to always read the "Details and Options" part of the documentation. $\endgroup$
    – rhermans
    Commented Sep 12, 2014 at 13:57
2
$\begingroup$

The function BinCountsallows you to specify variable bin sizes.

BarChart[
   BinCounts[RandomVariate[PoissonDistribution[2],10000], {{0, 1, 2, 3, 4, 5, 6, 8, 10}}],
   BarSpacing -> None, Frame -> True]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.