-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_functions.py
77 lines (55 loc) · 2.22 KB
/
plot_functions.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
65
66
67
68
69
70
71
72
73
74
75
76
77
import numpy as np
import matplotlib.font_manager
import matplotlib.pyplot as plt
def plot_bigrams(input_array, axis_option=None, fullscreen=None):
matplotlib.rcParams['font.family'] = "Segoe UI Historic"
bigram_table = np.zeros((29, 29), dtype=np.int32)
for index in range(len(input_array) - 1):
bigram_table[input_array[index], input_array[index + 1]] += 1
fig, ax = plt.subplots()
ax.matshow(bigram_table, cmap=plt.cm.jet)
sx = ax.secondary_xaxis('bottom')
sy = ax.secondary_yaxis('right')
ax.set_xticks(np.arange(29))
ax.set_yticks(np.arange(29))
sx.set_xticks(np.arange(29))
sy.set_yticks(np.arange(29))
ax.set_xticklabels(latin_ticks())
ax.set_yticklabels(latin_ticks())
if axis_option == 'runes':
sx.set_xticklabels(rune_ticks())
sy.set_yticklabels(rune_ticks())
for i in range(29):
for j in range(29):
c = bigram_table[j, i]
ax.text(i, j, str(c), va='center', ha='center')
if fullscreen:
plot_fullscreen()
plt.show()
def plot_letter_frequency(input_array, axis_option=None):
matplotlib.rcParams['font.family'] = "Segoe UI Historic"
_, counts = np.unique(input_array, return_counts=True)
if len(counts) != 29:
counts = np.zeros(29)
for number in range(29):
counts[number] = np.sum(input_array == number)
fig, ax = plt.subplots()
plt.plot(np.arange(29), counts)
ax.set_xticks(np.arange(29))
ax.set_xlim(left=0, right=28)
if axis_option == 'runes':
ax.set_xticklabels(rune_ticks())
if axis_option == 'latin':
ax.set_xticklabels(latin_ticks())
plt.tight_layout()
plt.show()
def latin_ticks():
return ['F', 'V', 'TH', 'O', 'R', 'C', 'G', 'W', 'H', 'N', 'I', 'J', 'EO', 'P', 'X', 'S', 'T', 'B', 'E', 'M', 'L',
'ING', 'OE',
'D', 'A', 'AE', 'Y', 'IA', 'EA']
def rune_ticks():
return ['ᚠ', 'ᚢ', 'ᚦ', 'ᚩ', 'ᚱ', 'v', 'ᚷ', 'ᚹ', 'ᚻ', 'ᚾ', 'ᛁ', 'ᛄ', 'ᛇ', 'ᛈ', 'ᛉ', 'ᛋ', 'ᛏ', 'ᛒ', 'ᛖ', 'ᛗ', 'ᛚ',
'ᛝ', 'ᛟ', 'ᛞ', 'ᚪ', 'ᚫ', 'ᚣ', 'ᛡ', 'ᛠ ']
def plot_fullscreen():
manager = plt.get_current_fig_manager()
manager.window.showMaximized()