Ai
1 Star 0 Fork 0

baihaowen/js可视爬取

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
start.py 872 Bytes
一键复制 编辑 原始数据 按行查看 历史
baihaowen 提交于 2024-04-10 16:08 +08:00 . first commit
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# 初始化一个空列表存储文本数据
data = []
# 逐行读取 JSON 文件的文本数据
with open('data.json', 'r', encoding='utf-8') as file:
for line in file:
data.append(line.strip()) # 去除每行文本开头和结尾的空白字符
# 将文本数据合并成一个长字符串
text_data = ' '.join(data)
# 指定中文字体文件路径
font_path = 'msyh.ttc' # 替换为您下载的中文字体文件路径
# 创建词云对象并生成词云图
wordcloud = WordCloud(font_path=font_path, width=800, height=400, background_color='white').generate(text_data)
# 显示词云图
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
# 保存词云图为 word-cloud.png 文件
plt.savefig('word-cloud.png')
# 显示词云图
plt.show()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/baihaowen/javascript-visual-crawling.git
git@gitee.com:baihaowen/javascript-visual-crawling.git
baihaowen
javascript-visual-crawling
js可视爬取
master

搜索帮助