Skip to content

Commit

Permalink
add knock39
Browse files Browse the repository at this point in the history
  • Loading branch information
Vita112 committed Jul 22, 2022
1 parent 21a12f2 commit 1e81b8b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions wei/chapter04/knock39.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
""'''
39. Zipfの法則
単語の出現頻度順位を横軸,その出現頻度を縦軸として,
両対数グラフをプロットせよ.'''

import math
from knock30 import load_result
from knock35 import sort_frequency
import matplotlib.pyplot as plt
import japanize_matplotlib



if __name__ == '__main__':
mecabfile = '../data/neko.txt.mecab'
nekodata = load_result(mecabfile)
ans = sort_frequency(nekodata)


ranks = [r + 1 for r in range(len(ans))]
cnts = [i[1] for i in ans]
plt.figure(figsize=(8, 4))
plt.scatter(ranks, cnts)
plt.xscale('log')
plt.yscale('log')
plt.xlabel('出現頻度順位')
plt.ylabel('出現頻度')
plt.show()

0 comments on commit 1e81b8b

Please sign in to comment.