
# How to make a histogram plot with raw data

# Input data:
grades = [83,95,91,87,70,0,85,82,100,67,73,77,0]
print(grades)


# Round grade to nearest 10
# decile = lambda grade: grade // 10 * 10
def decile(grade):
    return (grade // 10) * 10

rounded_grades = [decile(grade) for grade in grades]
print(rounded_grades)


from collections import Counter

histogram_data = Counter(rounded_grades)
print(histogram_data)

# Plot a histogram using histogram_data

from matplotlib import pyplot as plt

plt.bar([x - 0 for x in histogram_data.keys()], # -4 shifts each bar to the left by 4
         histogram_data.values(),               # give each bar its correct height
         8)                                     # give each bar a width of 8

plt.axis([-5, 105, 0, 5]) 	# x-axis from -5 to 105,
				# y-axis from 0 to 5

# Write out the ticks on x,y axis
plt.xticks([10 * i for i in range(11)]) # label x-axis ticks at 0, 10, ..., 100
plt.yticks([i for i in range(6)]) 	# label y-axis ticks at 0, 1, ..., 5

# Write out the labels on x,y axis
plt.xlabel("Decile")
plt.ylabel("# of Students")

plt.title("Distribution of Exam 1 Grades")

plt.show()
