[Visualization] Word Cloud

2023. 6. 4. 01:43Visualization

from wordcloud import WordCloud
import matplotlib.pyplot as plt
from collections import Counter
from konlpy.tag import Okt
from PIL import Image
import numpy as np
with open('대한민국헌법.txt', 'r', encoding='utf-8') as f:
    text = f.read()

okt = Okt()
nouns = okt.nouns(text) # 명사만 추출

words = [n for n in nouns if len(n) > 1] # 단어의 길이가 1개인 것은 제외

c = Counter(words) # 위에서 얻은 words를 처리하여 단어별 빈도수 형태의 딕셔너리 데이터를 구함

 

wc = WordCloud(font_path='malgun', width=400, height=400, scale=2.0, max_font_size=250)
gen = wc.generate_from_frequencies(c)
plt.figure()
plt.imshow(gen)

 

* 데이터 파일

대한민국헌법.txt
0.04MB

'Visualization' 카테고리의 다른 글

[Visualization] Bar Chart  (0) 2023.06.04
[Visualization] Pie Chart  (1) 2023.06.04
[Visualization] Line Chart  (1) 2023.06.04