Python:词云生成

今天刚刚学习到的Python词云生成


import jieba
import matplotlib.pyplot as plt
from wordcloud import WordCloud

text = open(r'.\aaa.txt','r').read()
#其中r防止转义
#print(text)
cut_text = jieba.cut(text)
#切分文字
result = ' '.join(cut_text)

wc = WordCloud(
    font_path=r'.\经典超圆简.ttf',
    #导入ttf格式的字体
    background_color = 'white',
    width = 500,
    max_font_size = 50,
    min_font_size = 10,
)
wc.generate(result)
wc.to_file(r'.\word.png')

Python:词云生成_第1张图片

你可能感兴趣的:(pycharm)