练习词云,就用我的偶像,郭嘉了。哈哈
import jieba
from wordcloud import WordCloud
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
img = Image.open(‘python.jpg’)
img_array = np.array(img)
file = open(‘gj.txt’,’r’).read()
cut = jieba.cut(file)
cut_content = ’ ‘.join(cut)
wc = WordCloud(
background_color=’white’,
mask=img_array,
font_path=”simhei.ttf”
)
wc.generate(cut_content)
wc.to_file(‘guojia.png’)
plt.figure(‘鬼才’)
plt.imshow(wc)
plt.axis(‘off’)
plt.show()