본문 바로가기

Python/시각화

시각화_04. 워드클라우드01

반응형
day4_워드클라우드

워드 클라우드란?

메타 데이터에서 얻어진 텍스트들을 분석하여 중요도나 인기도 등을 고려하여 시각적으로 늘어 놓아 표시하는 것이다. 보통은 2차원의 표와 같은 형태로 태그들이 배치되며 이때 순서는 알파벳/가나다 순으로 배치 된다. 시각적인 중요도를 강조를 위해 그 중요도에 따라 글자의 색상이나 굵기등 형태가 변한다.

https://amueller.github.io/word_cloud/index.html

설치 : 터미널창 이용

conda install -c conda-forge wordcloud

conda list

환경 설정

In [5]:
import matplotlib.pyplot as plt

import wordcloud
from wordcloud import WordCloud, STOPWORDS

# 한글 폰트 패스로 지정 
import matplotlib.font_manager as fm
path = 'C:\Windows\Fonts\malgunbd.ttf'
font_name = fm.FontProperties(fname=path).get_name()
plt.rc('font', family=font_name)

# 자동 크기 설정 
%matplotlib inline
In [6]:
wordcloud.__version__
Out[6]:
'1.5.0'

사용할 텍스트 설정

In [9]:
text = """
I can show you the world
Shining, shimmering splendid
Tell me, princess, now when did
You last let your heart decide?
I can open your eyes
Take you wonder by wonder
Over sideways and under
On a magic carpet ride
A whole new world
A new fantastic point of view
No one to tell us no
Or where to go
Or say we're only dreaming
A whole new world
A dazzling place I never knew
But when I'm way up here
It's crystal clear
That now I'm in a whole new world with you
Now I'm in a whole new world with you
Unbelievable sights
Indescribable feeling
Soaring, tumbling, freewheeling
Through an endless diamond sky

"""

워드 클라우드 설정

In [10]:
wordcloud = WordCloud(max_font_size=300,
                      font_path='C:\Windows\\Fonts\\malgunbd.ttf',
                      stopwords=STOPWORDS,
                      background_color='#FFFFFF',
                      width=600,height=600).generate(text)

사이즈 설정

In [26]:
plt.figure(figsize=(10,8))
plt.imshow(wordcloud)
# 크기와 관련된 옵션 
plt.tight_layout(pad=0)
plt.axis('off')
# 저장
plt.savefig('file.png', bbox_inches='tight')
반응형

'Python > 시각화' 카테고리의 다른 글

시각화_05. 워드클라우드02  (0) 2019.08.26
시각화_03  (0) 2019.08.26
시각화_02. matplotlib  (0) 2019.08.26
시각화_01. seaborn  (0) 2019.08.26