zoukankan      html  css  js  c++  java
  • wordcloud库基本介绍

    一.wordcloud库基本介绍

    1.1 wordcloud的作用

    wordcloud是优秀的词云展示第三方库

    1.2wordcloud库的安装
    pip install wordcloud

    二.wordcloud库使用说明

    2.1wordcloud库常规方法

    1.配置对象参数

    2.加载词云文本

    3.输出词云文件

    w = wordcloud.WordCloud()
    w.generate(文本等内容) #向WordCloud对象中记载文本内容
    w.to_file(文件名) #将词云输出为图像文件
    from wordcloud import WordCloud
    w = WordCloud()
    w.generate('python and wordcloud')
    w.to_file('1.png')

    import wordcloud
    w = wordcloud.WordCloud()
    w.generate('python and wordcloud')
    w.to_file('1.png')
    2.2 配置对象

     

    import jieba  #导入jieba库
    from wordcloud import WordCloud #从wordcloud中取出WordCloud对象
    from scipy.misc import imread
    import matplotlib.pyplot as plt
    f = open('美文.txt', 'r', encoding='utf8')
    data = f.read()
    result = ' '.join(jieba.lcut(data))
    f.close()
    color_mask = imread('兔子.jpg')
    wc = WordCloud(
       font_path=r'C:WindowsFontsSTXINGKA',
       width=1000,
       height=800,
       mask=color_mask,
       background_color='white'
    )
    wc.generate(result)
    wc.to_file('bilbli.png')
    plt.imshow(wc)
    plt.show()

     

  • 相关阅读:
    Yantai
    Star War
    douban's woshang
    cannot change font's type in coreldraw
    LuXun said
    WaiTan
    free ubuntu disk前天就收到了寄来的光盘
    Winter Swimming
    before buy laptop买本本前,先来看看
    ubuntu beginer
  • 原文地址:https://www.cnblogs.com/a736659557/p/11778311.html
Copyright © 2011-2022 走看看