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.
29 lines
849 B
29 lines
849 B
6 months ago
|
# -*- coding: utf-8 -*-
|
||
|
"""
|
||
|
Created on Mon Jun 10 18:48:47 2024
|
||
|
|
||
|
@author: Peter
|
||
|
"""
|
||
|
from wordcloud import WordCloud
|
||
|
import matplotlib.pyplot as plt
|
||
|
from wordcloud import STOPWORDS
|
||
|
from matplotlib.font_manager import FontProperties
|
||
|
import jieba
|
||
|
font_path = "C:/Windows/Fonts/SimHei.ttf"
|
||
|
font_prop = FontProperties(fname=font_path, size=14)
|
||
|
with open(r'C:\jieba-python\中文\yyy.txt', encoding='gb18030') as file:
|
||
|
txt = file.read()
|
||
|
words = " ".join(jieba.cut(txt, cut_all=False))
|
||
|
wordcloud = WordCloud(
|
||
|
font_path=font_path,
|
||
|
width=800,
|
||
|
height=400,
|
||
|
background_color='white',
|
||
|
stopwords=STOPWORDS
|
||
|
).generate(words)
|
||
|
|
||
|
plt.figure(figsize=(15, 10))
|
||
|
plt.imshow(wordcloud, interpolation='bilinear')
|
||
|
plt.axis('off')
|
||
|
plt.savefig(r'C:\jieba-python\中文\yyy.png', dpi=300, bbox_inches='tight')
|
||
|
plt.close()
|