Python WordCloud入门攻略

 时间:2026-04-26 15:21:35

1、到lfd.uci.edu/~gohlke/pythonlibs/#worldcloud里面下载与电脑系统和python版本相对应的wordcloud模块,具体安装步骤可以参考《怎么为python安装wordcloud模块?》

Python WordCloud入门攻略

2、准备一个txt文档,里面全是英文。

Python WordCloud入门攻略

3、制作文字云:

from wordcloud import WordCloud

f = open('0.txt','r').read()

wd = WordCloud(background_color='white',

               width=500,height=365,

               margin=2).generate(f)

wd.to_file('0.jpg')

Python WordCloud入门攻略

4、准备一张图片,作为文字云的背景图案。

Python WordCloud入门攻略

5、用上图为背景,绘制文字云:

from wordcloud import WordCloud

import cv2

f = open('0.txt','r').read()

mk = cv2.imread('0.png')

wd = WordCloud(mask=mk,background_color='white',

               width=500,height=365,

               margin=2).generate(f)

wd.to_file('000.png')

Python WordCloud入门攻略

  • 如何使用python语言pandas模块特殊方法创建矩阵
  • sketchpad5.06激活
  • 在pycharm中配置Anaconda的python工具包
  • python3 模块找不到No module named markupbase
  • python3 扩展方法
  • 热门搜索
    可是亲爱的你怎么不在我身边 契丹人是现在哪里人 如何抢票 上海著名旅游景点 四平旅游 aboboo怎么用 如何盘玩小叶紫檀 贷款卡怎么办理 二建增项怎么报名 路由器的ip地址