Python制作词云--(中文和英文都可)

2024-02-08 18:20

本文主要是介绍Python制作词云--(中文和英文都可),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.英文

词语:

 First, I want to tell you how proud we are. Getting into Columbia is a real testament of what a great well-rounded student you are. Your academic, artistic, and social skills have truly blossomed in the last few years. Whether it is getting the highest grade in Calculus, completing your elegant fashion design, successfully selling your painted running shoes, or becoming one of the top orators in Model United Nations, you have become a talented and accomplished young woman. You should be as proud of yourself as we are.I will always remember the first moment I held you in my arms. I felt a tingling sensation that directly touched my heart. It was an intoxicating feeling I will always have. It must be that "father-daughter connection" which will bind us for life. I will always remember singing you lullaby while I rocked you to sleep. When I put you down, it was always with both relief (she finally fell asleep!) and regret (wishing I could hold you longer). And I will always remember taking you to the playground, and watching you having so much fun. You were so cute and adorable, and that is why everybody loved you so.You have been a great kid ever since you were born, always quiet, empathetic, attentive, and well-mannered. You were three when we built our house. I remember you quietly followed us every weekend for more than ten hours a day to get building supplies. You put up with that boring period without a fuss, happily ate hamburgers every meal in the car, sang with Barney until you fell asleep. When you went to Sunday Chinese school, you studied hard even though it was no fun for you. I cannot believe how lucky we are as parents to have a daughter like you.You have been an excellent elder sister. Even though you two had your share of fights, the last few years you have become best friends. Your sister loves you so much, and she loves to make you laugh. She looks up to you, and sees you as her role model. As you saw when we departed, she misses you so much. And I know that you miss her just as much. There is nothing like family, and other than your parents, your sister is the one person who you can trust and confide in. She will be the one to take care of you, and the one you must take care of. There is nothing we wish more than that your sisterhood will continue to bond as you grow older, and that you will take care of each other throughout your lives. For the next four years, do have a short video chat with her every few days, and do email her when you have a chance.

代码

# -*- coding: utf-8 -*-
"""
Created on Sun Oct 25 17:55:21 2020@author: Dell
"""
import matplotlib.pyplot as plt
import jieba
from wordcloud import WordCloudtext = open(r'ciyun1.txt', "r").read()
cut_text = jieba.cut(text)
result = " ".join(cut_text)
colormap='pink'
wc = WordCloud(background_color='white',# 设置背景宽width=1600,# 设置背景高height=1550,# 最大字体max_font_size=750,# 最小字体min_font_size=30,mode='RGBA'#colormap='pink')
# 产生词云
wc.generate(result)
# 保存图片
wc.to_file(r"ciyun1.png") 
plt.imshow(wc)
plt.axis("off")
plt.show()

结果:

 

2.中文

词语:

首先,我想告诉你我们为你感到特别骄傲。进入哥伦比亚大学证明你是一个全面发展的优秀学生,你的学业、艺术和社交技能最近都有卓越的表现,无论是你在微积分上得了最高分,完成自己典雅的时尚的设计,成功卖出绘制的跑鞋,还是在“模拟联合国”演说中成为表现最突出的人之一,你毫无疑问已经是一个多才多艺的女孩。你的父母为你感到骄傲,你也应该像我们一样为自己感到自豪。
我会永远记得第一次将你抱在臂弯的那一刻,一种新鲜激动的感觉瞬间触动了我的心,那是一种永远让我陶醉的感觉,就是那种将我们的一生都联结在一起的“父女情结”。我也常常想起我唱着催眠曲轻摇你入睡,当我把你放下的时候,常常觉得既解脱又惋惜,一方面我想,她终于睡着了!另一方面,我又多么希望自己可以多抱你一会儿。我还记得带你到运动场,看着你玩得那么开心,你是那样可爱,所有人都非常爱你。
不但长得可爱,而且是个特别乖巧的孩子。你从不吵闹、为人着想,既听话又有礼貌。当你三岁我们建房子的时候,每个周末十多个小时你都静静地跟着我们去运建筑材料,三餐在车上吃着汉堡,唱着儿歌,唱累了就睡觉,一点都不娇气不抱怨。你去上周日的中文学习班时,尽管一点也不觉得有趣,却依然很努力。我们做父母的能有像你这样的女儿真的感到非常幸运。

代码:

import wordcloud #导入词云库
import numpy as np
import matplotlib.pyplot as plt
import PIL
import jieba
import re
with open(r'ciyun2.txt',encoding='utf8') as f:text1 = f.readlines()
#导入图片
image1 = PIL.Image.open(r's.jpg')
MASK = np.array(image1)
WC = WordCloud(scale=4,font_path='msyh.ttf',mask=MASK,background_color='white',max_words =300,max_font_size =160,random_state=20).generate(wl_space_split)
st1 = re.sub('[,。、“”‘ ’]','',str(text1)) #使用正则表达式将符号替换掉。
conten = ' '.join(jieba.lcut(st1)) #此处分词之间要有空格隔开,联想到英文书写方式,每个单词之间都有一个空格。
con = WC.generate(conten)
con.to_file(r"ciyun2.png") 
plt.imshow(con)
plt.axis("off")

结果: 

 

这篇关于Python制作词云--(中文和英文都可)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/691826

相关文章

python常见环境管理工具超全解析

《python常见环境管理工具超全解析》在Python开发中,管理多个项目及其依赖项通常是一个挑战,下面:本文主要介绍python常见环境管理工具的相关资料,文中通过代码介绍的非常详细,需要的朋友... 目录1. conda2. pip3. uvuv 工具自动创建和管理环境的特点4. setup.py5.

Python常用命令提示符使用方法详解

《Python常用命令提示符使用方法详解》在学习python的过程中,我们需要用到命令提示符(CMD)进行环境的配置,:本文主要介绍Python常用命令提示符使用方法的相关资料,文中通过代码介绍的... 目录一、python环境基础命令【Windows】1、检查Python是否安装2、 查看Python的安

Python UV安装、升级、卸载详细步骤记录

《PythonUV安装、升级、卸载详细步骤记录》:本文主要介绍PythonUV安装、升级、卸载的详细步骤,uv是Astral推出的下一代Python包与项目管理器,主打单一可执行文件、极致性能... 目录安装检查升级设置自动补全卸载UV 命令总结 官方文档详见:https://docs.astral.sh/

Python并行处理实战之如何使用ProcessPoolExecutor加速计算

《Python并行处理实战之如何使用ProcessPoolExecutor加速计算》Python提供了多种并行处理的方式,其中concurrent.futures模块的ProcessPoolExecu... 目录简介完整代码示例代码解释1. 导入必要的模块2. 定义处理函数3. 主函数4. 生成数字列表5.

Python中help()和dir()函数的使用

《Python中help()和dir()函数的使用》我们经常需要查看某个对象(如模块、类、函数等)的属性和方法,Python提供了两个内置函数help()和dir(),它们可以帮助我们快速了解代... 目录1. 引言2. help() 函数2.1 作用2.2 使用方法2.3 示例(1) 查看内置函数的帮助(

Python虚拟环境与Conda使用指南分享

《Python虚拟环境与Conda使用指南分享》:本文主要介绍Python虚拟环境与Conda使用指南,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、python 虚拟环境概述1.1 什么是虚拟环境1.2 为什么需要虚拟环境二、Python 内置的虚拟环境工具

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

Python pip下载包及所有依赖到指定文件夹的步骤说明

《Pythonpip下载包及所有依赖到指定文件夹的步骤说明》为了方便开发和部署,我们常常需要将Python项目所依赖的第三方包导出到本地文件夹中,:本文主要介绍Pythonpip下载包及所有依... 目录步骤说明命令格式示例参数说明离线安装方法注意事项总结要使用pip下载包及其所有依赖到指定文件夹,请按照以

Python实现精准提取 PDF中的文本,表格与图片

《Python实现精准提取PDF中的文本,表格与图片》在实际的系统开发中,处理PDF文件不仅限于读取整页文本,还有提取文档中的表格数据,图片或特定区域的内容,下面我们来看看如何使用Python实... 目录安装 python 库提取 PDF 文本内容:获取整页文本与指定区域内容获取页面上的所有文本内容获取

基于Python实现一个Windows Tree命令工具

《基于Python实现一个WindowsTree命令工具》今天想要在Windows平台的CMD命令终端窗口中使用像Linux下的tree命令,打印一下目录结构层级树,然而还真有tree命令,但是发现... 目录引言实现代码使用说明可用选项示例用法功能特点添加到环境变量方法一:创建批处理文件并添加到PATH1