You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
848 B

# -*- codeing utf-8 -*-
# @Time :2021/11/613:48
# @Author :1900301218
# @File :picture.py
# @Software :PyCharm
from wordcloud import WordCloud
import cv2
import jieba
import matplotlib.pyplot as plt
with open('pythonworkinfo.txt', 'r') as f:
text = f.read()
cut_text = " ".join(jieba.cut(text))
color_mask = cv2.imread('hh.jpg')
cloud = WordCloud(
# 设置字体,不指定就会出现乱码
font_path=" C:\\Windows\\Fonts\\simsun.ttc",
# font_path=path.join(d,'simsun.ttc'),
# 设置背景色
background_color='white',
# 词云形状
mask=color_mask,
# 允许最大词汇
max_words=2000,
# 最大号字体
max_font_size=40
)
wCloud = cloud.generate(cut_text)
wCloud.to_file('cloud.jpg')
plt.imshow(wCloud, interpolation='bilinear')
plt.axis('off')
plt.show()