网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

Python WordCloud入门攻略

时间:2024-10-12 08:34:22

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

Python WordCloud入门攻略

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

Python WordCloud入门攻略

3、制作文字云:from wordcloud import WordCloudf = 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 WordCloudimport cv2f = open(&垆杪屑丝#39;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入门攻略
© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com