You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
1.1 KiB
Python
24 lines
1.1 KiB
Python
6 years ago
|
from collections import Counter
|
||
|
from matplotlib import pyplot as plt
|
||
|
|
||
|
num_friends = [100, 49, 41, 40, 25, 21, 21, 19, 19, 18, 18, 16, 15, 15, 15, 15, 14, 14, 13, 13, 13, 13, 12, 12, 11, 10,
|
||
|
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||
|
9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6,
|
||
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4,
|
||
|
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||
|
3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||
|
1, 1, 1, 1, 1, 1, 1, 1]
|
||
|
|
||
|
friend_counts = Counter(num_friends)
|
||
|
|
||
|
xs = range(101) # largest value is just 100
|
||
|
ys = [friend_counts[x] for x in xs] # Height is just number of friends
|
||
|
plt.bar(xs, ys)
|
||
|
plt.axis([0, 101, 0, 25])
|
||
|
plt.title('Histogram of friend counts')
|
||
|
plt.xlabel('# of Friends')
|
||
|
plt.ylabel('# of People')
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
plt.show()
|