!pip install wordcloud
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
import re
import collections
from time import sleep
spwords = set(STOPWORDS) # Exception word set
spwords.add(',') #Exception Word
spwords.add('내가') #add word like this
wc1 = WordCloud(max_font_size=200, stopwords=spwords,font_path='./NanumGothic.ttf',background_color='white', width=800, height=800) #font file direction setup
str_text = ""
while True:
str_temp = input("당신이 원하는 단어를 입력하세요 : ")
str_text = str_text + "," + str_temp #string concat
print(str_text) #Check input data - it can save to txt file
wc1.generate(str_text)
plt.figure(figsize=(10, 8))
plt.imshow(wc1)
plt.tight_layout(pad=0)
plt.axis('off')
plt.axis('off')
plt.show()
plt.pause(1)
plt.close()
sleep(3)
Result
("쿠씨" 입력과 "내가" 제외의 상황('내가')라는 단어는 출력되지 않음)
댓글 없음:
댓글 쓰기