热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

python输出字体的大小_好玩又使用,使用Python生成漂亮的词云

词云是一种数据可视化技术,用于表示文本数据,其中每个单词的大小表示其出现的频率或重要性。可以使用词云突出显示重要的文本数据点。词云被广泛用于分析来自社交
词云是一种数据可视化技术,用于表示文本数据,其中每个单词的大小表示其出现的频率或重要性。可以使用词云突出显示重要的文本数据点。词云被广泛用于分析来自社交网络网站的数据。为了在Python中生成词云,需要的模块是– matplotlib,pandas和wordcloud。要安装这些软件包,请运行以下命令:pip install matplotlib
pip install pandas
pip install wordcloud代码1:字数可以设置要在tagcloud上显示的最大单词数。为此,请使用WordCloud()函数的max_words关键字参数。

# importing the necessery modulesfrom wordcloud import WordCloudimport matplotlib.pyplot as pltimport csv# file object is created
file_ob = open(r"linuxidc.com.csv")# reader object is created
reader_ob = csv.reader(file_ob)# contents of reader object is stored .# data is stored in list of list format.
reader_contents = list(reader_ob)# empty string is declare
text = ""# iterating through list of rowsfor row in reader_contents :# iterating through words in the rowfor word in row :# concatenate the words
text = text + " " + word# show only 10 words in the wordcloud .
wordcloud = WordCloud(width=480, height=480, max_words=10).generate(text)# plot the WordCloud image
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()
输出如下图:cd96a9cd1c1cf3edbe26fecf08cef8ff.png代码2:删除一些单词可以删除一些我们不想显示的词。为此,请将这些单词传递给WordCloud()函数的停用词列表参数。

# importing the necessery modulesfrom wordcloud import WordCloudimport matplotlib.pyplot as pltimport csv# file object is created
file_ob = open(r"linuxidc.com.csv")# reader object is created
reader_ob = csv.reader(file_ob)# contents of reader object is stored .# data is stored in list of list format.
reader_contents = list(reader_ob)# empty string is declare
text = ""# iterating through list of rowsfor row in reader_contents :# iterating through words in the rowfor word in row :# concatenate the words
text = text + " " + word# remove Python , Matplotlib , Geeks Words from WordCloud .
wordcloud = WordCloud(width=480, height=480,
stopwords=["Python", "Matplotlib","Geeks"]).generate(text)# plot the WordCloud image
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()
输出效果如下:23d843edccded6bcaab4281833ec3955.png代码3:更改背景我们可以更改wordcloud背景的颜色。为此,请使用WordCloud()函数的background_color关键字参数。

# importing the necessery modulesfrom wordcloud import WordCloudimport matplotlib.pyplot as pltimport csv# file object is created
file_ob = open(r"linuxidc.com.csv")# reader object is created
reader_ob = csv.reader(file_ob)# contents of reader object is stored .# data is stored in list of list format.
reader_contents = list(reader_ob)# empty string is declare
text = ""# iterating through list of rowsfor row in reader_contents :# iterating through words in the rowfor word in row :# concatenate the words
text = text + " " + word
wordcloud = WordCloud(width=480, height=480, background_color="pink").generate(text)# plot the WordCloud image
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()
输出效果如下:71c35b75a99b097ef8fe256ecc44ea7b.png代码4:更改单词的颜色我们可以使用WordCloud()函数的colormap关键字参数来更改单词的颜色。

# importing the necessery modulesfrom wordcloud import WordCloudimport matplotlib.pyplot as pltimport csv# file object is created
file_ob = open(r"linuxidc.com.csv")# reader object is created
reader_ob = csv.reader(file_ob)# contents of reader object is stored .# data is stored in list of list format.
reader_contents = list(reader_ob)# empty string is declare
text = ""# iterating through list of rowsfor row in reader_contents :# iterating through words in the rowfor word in row :# concatenate the words
text = text + " " + word
wordcloud = WordCloud(width=480, height=480, colormap="Oranges_r").generate(text)# plot the WordCloud image
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()
输出效果如下:1e82f12a031ac35c2ea8ee42277e8f20.png代码5:设置最大和最小字体我们可以控制wordcloud的最小和最大字体大小。为此,请使用WordCloud()函数的max_font_size和min_font_size关键字参数。

# importing the necessery modulesfrom wordcloud import WordCloudimport matplotlib.pyplot as pltimport csv# file object is created
file_ob = open(r"linuxidc.com.csv")# reader object is created
reader_ob = csv.reader(file_ob)# contents of reader object is stored .# data is stored in list of list format.
reader_contents = list(reader_ob)# empty string is declare
text = ""# iterating through list of rowsfor row in reader_contents :# iterating through words in the rowfor word in row :# concatenate the words
text = text + " " + word
wordcloud = WordCloud(width=480, height=480, max_font_size=20, min_font_size=10).generate(text)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()
8b68dbe7150f63bfc32705e1fcbc6ff8.pngOK,暂时先这样,中文乱码解决等请继续关注我们Linux公社的Python专题栏目,谢谢阅读。304c5fdc93cd416598f19e4b92496efc.png商务合作联系:root@linuxidc.net长按或扫描左图识别二维码关注Linux公社公众微信号更多Python相关信息见Python 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=17
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx

本文永久更新链接地址:https://www.linuxidc.com/Linux/2019-12/161681.htm

42da6755e108a0f24cf60b7951c775d9.gif2e525c76908d5b8f56bbaccead0e21de.png支持就点下在看并转发朋友圈吧42da6755e108a0f24cf60b7951c775d9.gif



推荐阅读
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • Vagrant虚拟化工具的安装和使用教程
    本文介绍了Vagrant虚拟化工具的安装和使用教程。首先介绍了安装virtualBox和Vagrant的步骤。然后详细说明了Vagrant的安装和使用方法,包括如何检查安装是否成功。最后介绍了下载虚拟机镜像的步骤,以及Vagrant镜像网站的相关信息。 ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了logistic回归(线性和非线性)相关的知识,包括线性logistic回归的代码和数据集的分布情况。希望对你有一定的参考价值。 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • 学习SLAM的女生,很酷
    本文介绍了学习SLAM的女生的故事,她们选择SLAM作为研究方向,面临各种学习挑战,但坚持不懈,最终获得成功。文章鼓励未来想走科研道路的女生勇敢追求自己的梦想,同时提到了一位正在英国攻读硕士学位的女生与SLAM结缘的经历。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • 计算机存储系统的层次结构及其优势
    本文介绍了计算机存储系统的层次结构,包括高速缓存、主存储器和辅助存储器三个层次。通过分层存储数据可以提高程序的执行效率。计算机存储系统的层次结构将各种不同存储容量、存取速度和价格的存储器有机组合成整体,形成可寻址存储空间比主存储器空间大得多的存储整体。由于辅助存储器容量大、价格低,使得整体存储系统的平均价格降低。同时,高速缓存的存取速度可以和CPU的工作速度相匹配,进一步提高程序执行效率。 ... [详细]
  • WhenIusepythontoapplythepymysqlmoduletoaddafieldtoatableinthemysqldatabase,itdo ... [详细]
  • IOS开发之短信发送与拨打电话的方法详解
    本文详细介绍了在IOS开发中实现短信发送和拨打电话的两种方式,一种是使用系统底层发送,虽然无法自定义短信内容和返回原应用,但是简单方便;另一种是使用第三方框架发送,需要导入MessageUI头文件,并遵守MFMessageComposeViewControllerDelegate协议,可以实现自定义短信内容和返回原应用的功能。 ... [详细]
  • 本文介绍了在MFC下利用C++和MFC的特性动态创建窗口的方法,包括继承现有的MFC类并加以改造、插入工具栏和状态栏对象的声明等。同时还提到了窗口销毁的处理方法。本文详细介绍了实现方法并给出了相关注意事项。 ... [详细]
  • 本文总结了使用不同方式生成 Dataframe 的方法,包括通过CSV文件、Excel文件、python dictionary、List of tuples和List of dictionary。同时介绍了一些注意事项,如使用绝对路径引入文件和安装xlrd包来读取Excel文件。 ... [详细]
author-avatar
印度神油两性a
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有