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的Matplotlib库绘制一幅富有创意的“蛇年有福”艺术图,这幅图结合了数字,蛇形,花朵等装饰,需要的可以参考下... 目录1. 绘图的基本概念2. 准备工作3. 实现代码解析3.1 设置绘图画布3.2 绘制数字“2025”3.3

python使用watchdog实现文件资源监控

《python使用watchdog实现文件资源监控》watchdog支持跨平台文件资源监控,可以检测指定文件夹下文件及文件夹变动,下面我们来看看Python如何使用watchdog实现文件资源监控吧... python文件监控库watchdogs简介随着Python在各种应用领域中的广泛使用,其生态环境也

Python中构建终端应用界面利器Blessed模块的使用

《Python中构建终端应用界面利器Blessed模块的使用》Blessed库作为一个轻量级且功能强大的解决方案,开始在开发者中赢得口碑,今天,我们就一起来探索一下它是如何让终端UI开发变得轻松而高... 目录一、安装与配置:简单、快速、无障碍二、基本功能:从彩色文本到动态交互1. 显示基本内容2. 创建链

Java调用Python代码的几种方法小结

《Java调用Python代码的几种方法小结》Python语言有丰富的系统管理、数据处理、统计类软件包,因此从java应用中调用Python代码的需求很常见、实用,本文介绍几种方法从java调用Pyt... 目录引言Java core使用ProcessBuilder使用Java脚本引擎总结引言python

python 字典d[k]中key不存在的解决方案

《python字典d[k]中key不存在的解决方案》本文主要介绍了在Python中处理字典键不存在时获取默认值的两种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录defaultdict:处理找不到的键的一个选择特殊方法__missing__有时候为了方便起见,

使用Python绘制可爱的招财猫

《使用Python绘制可爱的招财猫》招财猫,也被称为“幸运猫”,是一种象征财富和好运的吉祥物,经常出现在亚洲文化的商店、餐厅和家庭中,今天,我将带你用Python和matplotlib库从零开始绘制一... 目录1. 为什么选择用 python 绘制?2. 绘图的基本概念3. 实现代码解析3.1 设置绘图画

Python pyinstaller实现图形化打包工具

《Pythonpyinstaller实现图形化打包工具》:本文主要介绍一个使用PythonPYQT5制作的关于pyinstaller打包工具,代替传统的cmd黑窗口模式打包页面,实现更快捷方便的... 目录1.简介2.运行效果3.相关源码1.简介一个使用python PYQT5制作的关于pyinstall

使用Python实现大文件切片上传及断点续传的方法

《使用Python实现大文件切片上传及断点续传的方法》本文介绍了使用Python实现大文件切片上传及断点续传的方法,包括功能模块划分(获取上传文件接口状态、临时文件夹状态信息、切片上传、切片合并)、整... 目录概要整体架构流程技术细节获取上传文件状态接口获取临时文件夹状态信息接口切片上传功能文件合并功能小

python实现自动登录12306自动抢票功能

《python实现自动登录12306自动抢票功能》随着互联网技术的发展,越来越多的人选择通过网络平台购票,特别是在中国,12306作为官方火车票预订平台,承担了巨大的访问量,对于热门线路或者节假日出行... 目录一、遇到的问题?二、改进三、进阶–展望总结一、遇到的问题?1.url-正确的表头:就是首先ur

基于Python实现PDF动画翻页效果的阅读器

《基于Python实现PDF动画翻页效果的阅读器》在这篇博客中,我们将深入分析一个基于wxPython实现的PDF阅读器程序,该程序支持加载PDF文件并显示页面内容,同时支持页面切换动画效果,文中有详... 目录全部代码代码结构初始化 UI 界面加载 PDF 文件显示 PDF 页面页面切换动画运行效果总结主