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快速搭建Markdown笔记发布系统

《利用Python快速搭建Markdown笔记发布系统》这篇文章主要为大家详细介绍了使用Python生态的成熟工具,在30分钟内搭建一个支持Markdown渲染、分类标签、全文搜索的私有化知识发布系统... 目录引言:为什么要自建知识博客一、技术选型:极简主义开发栈二、系统架构设计三、核心代码实现(分步解析

基于Python实现高效PPT转图片工具

《基于Python实现高效PPT转图片工具》在日常工作中,PPT是我们常用的演示工具,但有时候我们需要将PPT的内容提取为图片格式以便于展示或保存,所以本文将用Python实现PPT转PNG工具,希望... 目录1. 概述2. 功能使用2.1 安装依赖2.2 使用步骤2.3 代码实现2.4 GUI界面3.效

Python获取C++中返回的char*字段的两种思路

《Python获取C++中返回的char*字段的两种思路》有时候需要获取C++函数中返回来的不定长的char*字符串,本文小编为大家找到了两种解决问题的思路,感兴趣的小伙伴可以跟随小编一起学习一下... 有时候需要获取C++函数中返回来的不定长的char*字符串,目前我找到两种解决问题的思路,具体实现如下:

python连接本地SQL server详细图文教程

《python连接本地SQLserver详细图文教程》在数据分析领域,经常需要从数据库中获取数据进行分析和处理,下面:本文主要介绍python连接本地SQLserver的相关资料,文中通过代码... 目录一.设置本地账号1.新建用户2.开启双重验证3,开启TCP/IP本地服务二js.python连接实例1.

基于Python和MoviePy实现照片管理和视频合成工具

《基于Python和MoviePy实现照片管理和视频合成工具》在这篇博客中,我们将详细剖析一个基于Python的图形界面应用程序,该程序使用wxPython构建用户界面,并结合MoviePy、Pill... 目录引言项目概述代码结构分析1. 导入和依赖2. 主类:PhotoManager初始化方法:__in

Python从零打造高安全密码管理器

《Python从零打造高安全密码管理器》在数字化时代,每人平均需要管理近百个账号密码,本文将带大家深入剖析一个基于Python的高安全性密码管理器实现方案,感兴趣的小伙伴可以参考一下... 目录一、前言:为什么我们需要专属密码管理器二、系统架构设计2.1 安全加密体系2.2 密码强度策略三、核心功能实现详解

Python Faker库基本用法详解

《PythonFaker库基本用法详解》Faker是一个非常强大的库,适用于生成各种类型的伪随机数据,可以帮助开发者在测试、数据生成、或其他需要随机数据的场景中提高效率,本文给大家介绍PythonF... 目录安装基本用法主要功能示例代码语言和地区生成多条假数据自定义字段小结Faker 是一个 python

Python实现AVIF图片与其他图片格式间的批量转换

《Python实现AVIF图片与其他图片格式间的批量转换》这篇文章主要为大家详细介绍了如何使用Pillow库实现AVIF与其他格式的相互转换,即将AVIF转换为常见的格式,比如JPG或PNG,需要的小... 目录环境配置1.将单个 AVIF 图片转换为 JPG 和 PNG2.批量转换目录下所有 AVIF 图

Python通过模块化开发优化代码的技巧分享

《Python通过模块化开发优化代码的技巧分享》模块化开发就是把代码拆成一个个“零件”,该封装封装,该拆分拆分,下面小编就来和大家简单聊聊python如何用模块化开发进行代码优化吧... 目录什么是模块化开发如何拆分代码改进版:拆分成模块让模块更强大:使用 __init__.py你一定会遇到的问题模www.

详解如何通过Python批量转换图片为PDF

《详解如何通过Python批量转换图片为PDF》:本文主要介绍如何基于Python+Tkinter开发的图片批量转PDF工具,可以支持批量添加图片,拖拽等操作,感兴趣的小伙伴可以参考一下... 目录1. 概述2. 功能亮点2.1 主要功能2.2 界面设计3. 使用指南3.1 运行环境3.2 使用步骤4. 核