-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplot.py
More file actions
71 lines (49 loc) · 1.47 KB
/
plot.py
File metadata and controls
71 lines (49 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
# plot.py
#
# This file contains code to display
# graphs of various statistics,
# which can be obtained via functions
# defined in stats.py
#
# imports #
from matplotlib import pyplot as plt
# functions #
def __graph_chars(info):
'''
Given a tuple of summary stats,
such as that returned by the
report_summary function, this
function plots character
frequency data using matplotlib
'''
# retrieve info from summary tuple
v_counts = info[0]
c_counts = info[1]
v_counts.update(c_counts)
# set up data for x- and y-axes of data plot
x_labels = [x for x, _ in sorted(v_counts.items())]
x = list(range(len(v_counts)))
y = [y for _, y in sorted(v_counts.items())]
# plot bar graph of letter vs frequency
bar_width = 1/1.5
plt.bar(x, y, width=bar_width, tick_label=x_labels)
plt.show()
def __graph_words(info):
'''
This function is similar to the __graph_chars
function, except that it plots word frequencies
instead of character frequencies
'''
# retrieve appropriate summary stats
w_counts = info[2]
# set up data for x- and y-axes
x = list(range(len(w_counts)))
y = [c for _, c in sorted(w_counts.items())]
x_labels = [w for w, _ in sorted(w_counts.items())]
# plot frequencies on a bar graph
plt.xticks(x, x_labels, rotation='vertical')
bar_width = 1/1.5
plt.bar(x, y, width=bar_width)
plt.subplots_adjust(bottom=0.15)
plt.show()