-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgraph_1grams_cumshare_rank.py
60 lines (45 loc) · 1.85 KB
/
graph_1grams_cumshare_rank.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
# Create a graph of cumshare vs rank for 1-grams across languages
import pandas as pd
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter, PercentFormatter
###############################################################################
# Settings
langs = ["chinese_simplified", "english", "french", "german", "hebrew",
"italian", "russian", "spanish"]
langnames = ["Chinese", "English", "French", "German", "Hebrew",
"Italian", "Russian", "Spanish"]
###############################################################################
# Functions
def get_fig(use_dark):
d = pd.DataFrame()
for lang in langs:
d[lang] = pd.read_csv(f"ngrams/1grams_{lang}.csv",
usecols=['cumshare'], nrows=10000)
d.index = range(1, len(d)+1)
d.columns = langnames
plt.clf()
matplotlib.rcParams.update(matplotlib.rcParamsDefault)
sns.set_theme(style="whitegrid")
plt.rcParams.update({"grid.linewidth":0.5, "grid.alpha":0.6})
if use_dark:
plt.style.use("dark_background")
light_or_dark = "dark"
else:
light_or_dark = "light"
plot = sns.lineplot(data=d, palette="tab10", linewidth=1)
plot.legend(bbox_to_anchor=(0.001, 1.0), loc="upper left")
plot.set_xlabel("Most common words learned")
plot.set_ylabel("% words in a typical book one can understand")
plot.set(xscale="log")
plot.get_xaxis().set_major_formatter(ScalarFormatter())
plot.get_yaxis().set_major_formatter(PercentFormatter(xmax=1.0, symbol=''))
plt.xlim(1, 10000)
plt.ylim(0, 1)
plt.savefig(f"graph_1grams_cumshare_rank_{light_or_dark}.svg")
###############################################################################
# Run
if __name__ == '__main__':
get_fig(False)
get_fig(True)