Basic Charts
We are going to leverage numpy for a lot of the work in these lessons; it’s extremely fast and full of functionality. Let’s first establish an array that we will say is survey answers for ratings of this course, ranging from 0 to 4.
import numpy as np
answers = np.array([0, 2, 1, 0, 4, 2, 3, 1, 4, 1, 4, 2, 3])
The first numpy function we are going to use is bincount(), what it returns is a count for each non-negative integer in the range of our array.
print(np.bincount(answers))
What if we wanted to plot a histogram of this data? What we could do is create an x-axis range from 0 to the largest integer in the problem set as well as set our y-axis equal to the bin counts we just found.
vals = list(range(0,5))
counts = np.bincount(answers)
import matplotlib.pyplot as plt
plt.bar(vals,counts)
plt.show()
This dataset can be described as symmetric, the left and right sides are about the same size. It can also possibly be called a uniform distribution since the bars are all about the same size.
What if instead, we had this distribution….
answers = np.array([0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4])
vals = list(range(0,5))
counts = np.bincount(answers)
plt.bar(vals,counts)
plt.show()
This curve is bell shaped, what we call this in statistics is a normal distribution.