python生成默认的矩形词云图(原文件为英文)

我们接下来要完成这个效果

首先导入库:

import wordcloud                                                                    #导入词云库

wc = wordcloud.WordCloud()                                                 #创建词云对象

with open(r'这里输入自己文件所在的地址') as file:

        fr = file.read()

im = wc.generate(fr)                                                                 #用生成器方法加载文本

im.to_file('wordcloud.jpg')                                                         #将生成的词云图片保存在指定的文件夹里

im.to_image()                                                                           #显示输出词云图片

歌词内容如下:

"See You Again- Wiz Khalifa&Charlie Puth\nIt's Been A Long DayWithout You My Friend.\nAnd I'll Tell You AllAbout It When I See You Again.\nWe've Come A Long WayFrom Where We Began.\nOH I'll Tell You AllAbout It When I See You Again.\nWhen I See You Again~\n(RAP)\nDamn\nWho Knew\nAll The Planes We Flew\nGood Things We BeenThrough\nThat I'd Be StandingRight Here Talking To You About\nAnother Path I Know WeLoved To Hit The Road And Laugh\nBut Something Told MeThat It Wouldn't Last\nHad To Switch Up\nLook At Things DifferentSee The Bigger Picture\nThose Were The Days HardWork Forever Pays\nNow I See You In A BetterPlace.\nHow Could We Not TalkAbout Family When Family's All That We Got?\nEverything I Went ThroughYou Were Standing There By My Side\nAnd Now You Be With GonnaMe For The Last Ride.\nIt's Been A Long DayWithout You My Friend.\nAnd I'll Tell You AllAbout It When I See You Again.\nWe've Come A Long WayFrom Where We Began.\nOH I'll Tell You AllAbout It When I See You Again.\nWhen I See You Again~\n(RAP)\nFirst You Both Go OutYour Way\nAnd The Vibe Is FeelingStrong\nAnd What's Small Turn ToA friendship\nTurned Into A Bond AndThat Bond Will\nNever Be Broke And TheLove Will\nNever Get Lost.\nAnd When Brotherhood Come\nFirst Then The Line WillNever Be Crossed\nEstablished It On Our Own\nWhen That Line Had To BeDrawn\nAnd That Line Is\nWhat We Reached SoRemember Me When I'm Gone.\nHow Could We Not TalkAbout Family When Family's All That We Got?\nEverything I Went ThroughYou Were Standing There By My Side\nAnd Now You Be With GonnaMe For The Last Ride.\nLight Guide Your Way.\nHold Every Memory As YouGo\nAnd Every Road You Take\nO Will Always Lead YouHome.\nIt's Been A Long DayWithout You My Friend.\nAnd I'll Tell You AllAbout It When I See You Again.\nWe've Come A Long WayFrom Where We Began.\nOH I'll Tell You AllAbout It When I See You Again.\nWhen I See You Again~"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值