zoukankan      html  css  js  c++  java
  • python词云

    四行Python代码上手词云制作

    1号词云:《葛底斯堡演说》黑色背景词云(4行代码上手)

    import wordcloud
    w = wordcloud.WordCloud()
    w.generate('and that government of the people, by the people, for the people, shall not perish from the earth.')
    w.to_file('output1.png')

    运行完成之后,在代码所在的文件夹,就会出现output.png图片文件。可以看出,wordcloud自动将and that by the not from等废话词组过滤掉,并且把出现次数最多的people大号显示。

    # 1号词云:葛底斯堡演说黑色背景词云
    # B站专栏:同济子豪兄 2019-5-23
    # 导入词云制作第三方库wordcloud
    import wordcloud
    # 创建词云对象,赋值给w,现在w就表示了一个词云对象
    w = wordcloud.WordCloud()
    
    # 调用词云对象的generate方法,将文本传入
    w.generate('and that government of the people, by the people, for the people, shall not perish from the earth.')
    
    # 将生成的词云保存为output1.png图片文件,保存出到当前文件夹中
    w.to_file('output1.png')

    wordcloud库为每一个词云生成一个WordCloud对象(注意,此处的W和C是大写)

    也就是说,wordcloud.WordCloud()代表一个词云对象,我们将它赋值给w

    现在,这个w就是词云对象啦!我们可以调用这个对象。

    我们可以在WordCloud()括号里填入各种参数,控制词云的字体、字号、字的颜色、背景颜色等等。

    wordcloud库会非常智能地按空格进行分词及词频统计,出现次数多的词就大。

     

  • 相关阅读:
    hive函数之~字符串函数
    hive函数之~条件函数
    JSONP使用及注意事项小结
    css命名管理混乱?不妨试试BEM
    【移动端debug-6】如何做一个App里的web调试小工具
    ES6学习笔记(五):Class和Module
    ES6学习笔记(三):与迭代相关的新东东
    ES6学习笔记(四):异步操作
    ES6学习笔记(二):引用数据类型
    CORS跨域资源共享简述
  • 原文地址:https://www.cnblogs.com/huaobin/p/15692213.html
Copyright © 2011-2022 走看看