On Fri, Oct 22, 2010 at 9:40 AM, Christopher Fonnesbeck
<statist...@me.com> wrote:
> On Oct 22, 2010, at 9:13 AM, Ryan May wrote:
>>
>> On Fri, Oct 22, 2010 at 8:47 AM, Christopher Fonnesbeck
>> <statist...@me.com> wrote:
>>> I notice that when the number of bins in a histogram is sparse, the spacing 
>>> between the bins can be irregular. For example:
>>>
>>> http://cl.ly/7e0ad7039873d5446365
>>> http://cl.ly/c7cb20b567722928ac3c
>>>
>>> Is there a way of normalizing this, and better, can the default behavior 
>>> result in something more consistent (i.e. publication-quality)?
>>
>> That looks like some bizarre rounding/truncation or something like it.
>> Can you post an example (can just use made up data) that reproduces
>> this? I've not seen this before, so I sense it's due to the specific
>> data types you're passing in.
>
> Here is a very simple example. The data are just a list of integers:
>
> http://dl.dropbox.com/u/233041/histexample.py
>
> and it results in an odd choice of intervals.
>
> (array([863, 775,   0, 271,   0,  67,  23,   0,   0,   1]),
>  array([ 0. ,  0.6,  1.2,  1.8,  2.4,  3. ,  3.6,  4.2,  4.8,  5.4,  6. ]),
>  <a list of 10 Patch objects>)
>
> If there are only 7 possible values of the data, which are evenly-spaced, it 
> should probably not go in and create more than 6 bins as the default 
> behavior. I know I can specify bins by hand, but when automated it would be 
> nice to have a more sensible default.

It just defaults to creating 10 bins (which is identical to
numpy.histogram, which is what does the work under the hood.) If you
know how many bins you want, you can just do:

hist(x, bins=6)

This gives (for your example) the behavior you seem to want.  I don't
know of any way that would sensibly choose a number of bins
automatically, but I'd consider a patch that proves me wrong. :)

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to