In [3]:
import numpy as np
from scipy import stats

In [5]:
array = np.array([1, 1, 5, 0, 1, 2, 2, 0, 1, 4])

In [6]:
array = np.array(['gabriela', 'patrícia', 'samantha', 'gabriela'])

In [7]:
frequency = stats.itemfreq(array)
print(frequency)


[['gabriela' '2']
 ['patrícia' '1']
 ['samantha' '1']]

In [112]:
xi = frequency[:, 0]
print(xi)


['gabriela' 'patrícia' 'samantha']

In [116]:
fi = frequency[:, 1]
print(fi)


['2' '1' '1']

In [118]:
fi = fi.astype(int)
print(fi)


[2 1 1]

In [124]:
%matplotlib notebook
import matplotlib.pyplot as plt

x_pos = np.arange(len(xi))
plt.figure(1)
plt.bar(x_pos, fi, align='center')
plt.ylim(0, max(fi) + 0.5)
plt.xticks(np.arange(3), xi)


Out[124]:
([<matplotlib.axis.XTick at 0x7f965da29d30>,
  <matplotlib.axis.XTick at 0x7f965d95eef0>,
  <matplotlib.axis.XTick at 0x7f965dc50470>],
 <a list of 3 Text xticklabel objects>)

In [44]:
%matplotlib notebook
import matplotlib.pyplot as plt

x_pos = np.arange(len(xi))
print(x_pos)
plt.figure(1)
plt.bar(x_pos, fi,align='center')
plt.ylim(0, max(fi) + 0.5)
plt.xticks(np.arange(5), xi)
plt.xlabel("xi")
plt.ylabel("fi")


[0 1 2 3 4]
Out[44]:
<matplotlib.text.Text at 0x7f965e757a90>

In [ ]: