-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline_1.py
64 lines (47 loc) · 1.56 KB
/
line_1.py
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
from matplotlib import pyplot as plt
from matplotlib import rc
from nltk import FreqDist
words = ['morze', 'Polska', 'sklep', 'wiosna', 'morze', 'dziecko']
filenames = ["lord-jim.txt", "przedwiosnie.txt", "sklepy-cynamonowe.txt", "szewcy.txt", "ziemia-obiecana-tom-pierwszy.txt"]
titles = ["Lord Jim", "Przedwiośnie", "Sklepy cynamonowe", "Szewcy", "Ziemia obiecana Tom I"]
def line_plot(names, args):
plt.title("Liczba wystąpień słów")
plt.xlabel("Próbki")
plt.ylabel("Liczba wystąpień")
colors = ["b", "g", "r", "c", "m", "y", "k", "w"]
a = 0
for i in args:
plt.plot(args[a], color=colors[a%len(colors)], label=titles[a])
a += 1
# plt.plot(args[0], color='r', label=titles[0])
# plt.plot(args[1], color='b', label=titles[1])
plt.legend()
plt.grid()
plt.xticks(range(len(names)), names, rotation=90)
plt.tight_layout()
plt.savefig('plot.png')
plt.show()
def count_freq(fname):
with open(fname, encoding="utf8") as fp:
split_words = fp.read().split()
freq_dist = FreqDist(split_words)
return freq_dist
def return_values(words, freq):
result = []
for s in words:
result.append(freq[s] if s in freq else 0)
return result
def make_plot(words, args):
a = 0
fre = []
res = []
for i in args:
freq1 = count_freq(args[a])
fre.append(freq1)
res1 = return_values(words, fre[a])
res.append(res1)
a += 1
line_plot(words, res)
def color_lines(texts):
make_plot(words, filenames)
color_lines(filenames)