본문 바로가기

Python_Intermediate/WordCloud

Koera Constitution WordCloud

반응형

Python Code>

from wordcloud import WordCloud
from matplotlib import pyplot
from collections import Counter
from konlpy.tag import Okt
from PIL import Image
import numpy

text = ''
with open('데이터위치', encoding="utf-8") as f:
text = f.read();

nlp = Okt()

nouns = nlp.nouns(text)

words = []
for n in nouns:
if len(n) > 1:
words.append(n)

count = Counter(words)

most = count.most_common(100)

tags = {}
for n, c in most:
tags[n] = c

img = Image.open('배경위치')
img_array = numpy.array(img)

wc = WordCloud(background_color="white", font_path="NanumGothic", width=311, height=512,
scale=2.0, max_font_size=250, mask=img_array)

gen = wc.generate_from_frequencies(tags)

pyplot.figure()
pyplot.imshow(gen, interpolation='bilinear')
wc.to_file('결과물파일명')
pyplot.close()


O>


반응형

'Python_Intermediate > WordCloud' 카테고리의 다른 글

WordCloud Option Background image  (0) 2019.04.20
WordCloud Option Forbidden word  (0) 2019.04.20
WordCloud Basic  (0) 2019.04.20
WordCloud Module Import  (0) 2019.04.20
Alice WordCloud  (0) 2019.04.13