In [14]:
import numpy

import matplotlib # TODO bug in ipython? (sometime can't call the module directly)
from matplotlib import pyplot

import scipy
from scipy import stats
from scipy import optimize

%matplotlib inline

In [15]:
import math

def poissoniana(x, mu):
    return (numpy.exp(-mu) * mu**x)/ (scipy.misc.factorial(x)) # if x >= 0

In [16]:
x = numpy.linspace(1,1000,1000)
# y = poissoniana(x, 3)
y = dataframeGradi.Tre.values


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-16-4909f8ea593e> in <module>()
      1 x = numpy.linspace(1,1000,1000)
      2 # y = poissoniana(x, 3)
----> 3 y = dataframeGradi.Tre.values

NameError: name 'dataframeGradi' is not defined

In [17]:
popt, pcov = scipy.optimize.curve_fit(poissoniana, x, y)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-17-3aeb353885e1> in <module>()
----> 1 popt, pcov = scipy.optimize.curve_fit(poissoniana, x, y)

NameError: name 'y' is not defined

In [18]:
y, x = numpy.histogram(dataframeGradi.aggregati.values, bins = 3)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-18-c7af66a8b63a> in <module>()
----> 1 y, x = numpy.histogram(dataframeGradi.aggregati.values, bins = 3)

NameError: name 'dataframeGradi' is not defined

In [19]:
min(dataframeGradi.aggregati.values)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-19-7df1e88d3cbb> in <module>()
----> 1 min(dataframeGradi.aggregati.values)

NameError: name 'dataframeGradi' is not defined

In [20]:
len(y),len(x)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-20-a09dec0ae8ad> in <module>()
----> 1 len(y),len(x)

NameError: name 'y' is not defined

In [21]:
y,x


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-21-d5074b03e2ce> in <module>()
----> 1 y,x

NameError: name 'y' is not defined

In [22]:
arr = [5,5,5,5,5,6,6,6,7,7]

y, x = numpy.histogram(numpy.array(arr), bins=(5,6,7,8))

In [23]:
y,x


Out[23]:
(array([5, 3, 2]), array([5, 6, 7, 8]))

In [24]:
pyplot.hist(arr, bins=(5,6,7,8))


Out[24]:
(array([ 5.,  3.,  2.]), array([5, 6, 7, 8]), <a list of 3 Patch objects>)

In [25]:
pyplot.hist(arr, bins=3)


Out[25]:
(array([ 5.,  3.,  2.]),
 array([ 5.        ,  5.66666667,  6.33333333,  7.        ]),
 <a list of 3 Patch objects>)

In [26]:
pyplot.hist(arr, bins=3, align="left")


Out[26]:
(array([ 5.,  3.,  2.]),
 array([ 5.        ,  5.66666667,  6.33333333,  7.        ]),
 <a list of 3 Patch objects>)

In [27]:
pyplot.hist(arr, bins=(5,6,7,8), align="mid")


Out[27]:
(array([ 5.,  3.,  2.]), array([5, 6, 7, 8]), <a list of 3 Patch objects>)

In [28]:
pyplot.hist(arr, bins=(5,6,7,8), align="left")


Out[28]:
(array([ 5.,  3.,  2.]), array([5, 6, 7, 8]), <a list of 3 Patch objects>)

In [29]:
def integerHistogram(integerData):
    integerData = [5,5,5,5,5,6,6,6,7,7]
    minimum = min(integerData)
    maximum = max(integerData)
    integerBins = maximum - minimum + 1
    numberSet = numpy.linspace(minimum, maximum, integerBins)
    y, x = numpy.histogram(arr, bins=(5,6,7,8))

In [30]:
numpy.histogram(arr, bins=(5,6,7,8))


Out[30]:
(array([5, 3, 2]), array([5, 6, 7, 8]))

In [31]:
integerData = [5,5,5,5,5,6,6,6,7,7,9,10,10]
minimum = min(integerData)
maximum = max(integerData)
integerBins = maximum - minimum + 1
numberSet = numpy.linspace(minimum, maximum, integerBins, dtype=int)
min(integerData), max(integerData)


Out[31]:
(5, 10)

In [32]:
numberSet


Out[32]:
array([ 5,  6,  7,  8,  9, 10])

In [33]:
numpyBins = numberSet + [minimum+1]

In [34]:
numpyBins


Out[34]:
array([11, 12, 13, 14, 15, 16])

In [ ]: