tommyzihao / zihaowordcloud Goto Github PK
View Code? Open in Web Editor NEWsimple tutorials and examples of wordcloud-python
simple tutorials and examples of wordcloud-python
#coding=utf-8
import jieba
import wordcloud
# 构建并配置词云对象w,注意要加stopwords集合参数,将不想展示在词云中的词放在stopwords集合里,这里去掉“曹操”和“孔明”两个词
w = wordcloud.WordCloud(width=1000,
height=700,
background_color='white',
font_path='STHeiti Light.ttc',
scale=15,
stopwords={"曹操","孔明"})
# 对来自外部文件的文本进行中文分词,得到string
txtlist = jieba.lcut("曹操,我们今天取得了胜利ko 孔明,曹操,曹操的儿子,孔明的儿子,常胜将军哦,孔明肯定不行。")
string = " ".join(txtlist)
# 将string变量传入w的generate()方法,给词云输入文字
w.generate(string)
# 将词云图片导出到当前文件夹
w.to_file('output8-threekingdoms.png')
#coding=utf-8
import jieba
import wordcloud
# 构建并配置词云对象w
w = wordcloud.WordCloud(width=1000,
height=700,
background_color='white',
font_path='STHeiti Light.ttc',
scale=3,
stopwords={'我们','一个','可以', '这个','那个','自己','就是','问题','如果','用户','可能','些','这些','那些','需要','不同', '现在','通过', '不是', '还是', '所以', '能','因为','使用','他们','大家','应该','或者','时候','然后','一样','成为','其实','开始'})
# stopwords 貌似不能生效。
# 调用jieba的lcut()方法对原始文本进行中文分词,得到string
# 读取 reading 文章的所有文本内容
f = open('data.txt', 'r')
txt = f.read()
txtlist = jieba.lcut(txt)
string = " ".join(txtlist)
# 将string变量传入w的generate()方法,给词云输入文字
w.generate(string)
# 将词云图片导出到当前文件夹
w.to_file('reading_wordcloud_output.png')
生成之后出现乱码
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.