Giter Site home page Giter Site logo

zihaowordcloud's Issues

contour_width报错

在进行9号词云练习勾勒轮廓线时,构建词云对象时在contour_width=1处报错:TypeError: init() got an unexpected keyword argument 'contour_width'
contour_width报错

配置了 stopwords ,但是不能取消此词

#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')

生成之后出现乱码

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.