Skip to content

Instantly share code, notes, and snippets.

@woodongk
Last active May 26, 2020 04:46
Show Gist options
  • Save woodongk/9f3dffa7918de06913af1baae9a460cd to your computer and use it in GitHub Desktop.
Save woodongk/9f3dffa7918de06913af1baae9a460cd to your computer and use it in GitHub Desktop.
word cloud 만들기
def generate_circular_wordcloud(strings):
"""Returns circle shape Word Cloud
Example:
strings (str): "기억 니은 디귿 기억 기억"
strings (dict) {"기억":30, "니은":10, "디귿":1}
"""
# mask circle
x, y = np.ogrid[:1000, :1000]
mask = (x - 500) ** 2 + (y - 500) ** 2 > 480 ** 2
circle_mask = 255 * mask.astype(int)
# word cloud
wordcloud = WordCloud(max_font_size=200,
font_path='/Library/Fonts/NanumSquareExtraBold.ttf',
background_color="white",
width=1000,
height=1000,
max_words = 100,
mask=circle_mask,
colormap='Paired')
if type(strings)== str:
wordcloud.generate(strings)
elif type(strings) == dict:
wordcloud.generate_from_frequencies(strings)
else:
print("ValueError ! 인풋 타입이 잘못되었습니다")
return
plt.figure(figsize=(10,10))
plt.imshow(wordcloud, interpolation='bilinear')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment