Re: Histogram of floating point values.

Discussion in 'Python' started by Kurt Smith, Jul 25, 2008.

  1. Kurt Smith

    Kurt Smith Guest

    On Fri, Jul 25, 2008 at 5:02 PM, aditya shukla
    <> wrote:
    > Hello folks,
    >
    > I have a list say
    >
    > data=[0.99,0.98,0.98,0.98,0.97,0.93,0.92,0.92,0.83,0.66,0.50,0.50]
    >
    > i am trying to plot histogram of these values
    >
    > i have installed numpy and matplotlib and this is what i am doing*
    > import numpy
    > import pylab
    > from numpy import *
    > from pylab import *
    >
    > input_hist=array(data)
    > pylab.hist(input_hist,bins=0.1)
    > and this is the error that i am getting
    >
    > (array([], dtype=int32), array([ 0.5]), <a list of 0 Patch objects>)
    >
    >
    > does this mean that i cannot plot a histogram of floating point values ? or
    > is there a way around


    the 'bins' argument to pylab.hist() is supposed to be an integer or a
    list of the bins' lower edges. The default value is 10, more than
    that gives smaller bins, as one would expect. Take a look at the
    pylab.hist documentation (you can do 'print pylab.hist.__doc__' from
    the command interpreter).

    You should have no problem plotting a hist of floats. Try this:

    import numpy
    import pylab
    from numpy import *
    from pylab import *

    data=[0.99,0.98,0.98,0.98,0.97,0.93,0.92,0.92,0.83,0.66,0.50,0.50]

    input_hist=array(data)
    pylab.hist(input_hist)
    pylab.show()

    The last line will display the actual histogram. See the difference
    pylab.show and pylab.ion functions.

    In the future, it is advisable to post these questions to the
    matplotlib or the numpy/scipy users mailing lists.

    Kurt



    >
    > Thanks in advance
    >
    > Aditya
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Kurt Smith, Jul 25, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. H aka N
    Replies:
    15
    Views:
    15,643
    Ben Jones
    Mar 2, 2006
  2. Motaz Saad
    Replies:
    7
    Views:
    6,478
  3. Replies:
    4
    Views:
    1,282
    Default User
    Feb 22, 2006
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,321
    Saraswati lakki
    Jan 6, 2012
  5. teeshift
    Replies:
    2
    Views:
    249
    Chris Pearl
    Dec 1, 2006
Loading...

Share This Page