美文网首页
用python做了一个《游戏力》云图

用python做了一个《游戏力》云图

作者: 墨飞源源 | 来源:发表于2020-05-22 21:27 被阅读0次
《游戏力》云图

贴上源码

import numpy as np;

from PIL import Image

import re

import jieba

from wordcloud import WordCloud,ImageColorGenerator,STOPWORDS

#读取文件

with open('playfull power.txt',"r",encoding='utf-8') as f:

    word = (f.read());

    f.close();

#词云形状 字体

image = np.array(Image.open('1002.jpg'));

font = 'msyh.ttc';

#去掉英文

resultword = re.sub("[A-Za-z0-9\[\`\~\!\@\#\$\^\&\*\(\)\=\|\{\}\'\:\;\'\,\[\]\.\<\>\/\?\~\。\@\#\\\&\*\%]", "",word);

wordlist_from_jieba = jieba.cut(resultword)

wl_generate = " ".join(wordlist_from_jieba);

stop_words = set(STOPWORDS)

stop_words.add("如果");

stop_words.add("资料");

stop_words.add("搜索");

stop_words.add("一个");

stop_words.add("可以");

stop_words.add("可能");

stop_words.add("因为");

stop_words.add("或者");

stop_words.add("需要");

stop_words.add("但是");

stop_words.add("没有");

stop_words.add("一些");

stop_words.add("这些");

stop_words.add("不是");

stop_words.add("那么");

stop_words.add("这个");

stop_words.add("这样");

stop_words.add("什么");

my_wordcloud = WordCloud(scale=4,font_path=font,mask=image,stopwords=stop_words,background_color='white'

                        ,max_words=100).generate(wl_generate);

to_img = my_wordcloud.to_image();

to_img.show();

my_wordcloud.to_file("playfull power.jpg");

相关文章

网友评论

      本文标题:用python做了一个《游戏力》云图

      本文链接:https://www.haomeiwen.com/subject/yvwcahtx.html