zoukankan      html  css  js  c++  java
  • python 词云图简单示例

    一、安装 wordcloud

    pip  install wordcloud

    二、加载包、设置路径

    import os
    from wordcloud import WordCloud
    import matplotlib.pyplot as plt
    os.chdir('E:\pyspace\tmp')

    三、词云图示例

    1、默认参数示例

    text = 'Keep it simple and stupid.'
    wc = WordCloud()  # 实例化词云图对象
    
    wc.generate(text)  # 根据文本生成词云图
    plt.imshow(wc)  # 显示词云图

     如果 jupyter 没有图形输出,需要设置 jupyter 的图形显示方式

    %matplotlib inline

    WordCloud()  词云图对象对应的画布默认长200像素,宽400像素,背景色为黑色。

    2、配置参数示例

    text = 'Keep it simple and stupid.'
    wc = WordCloud(background_color='white', width=500, height=300)  # 实例化词云图对象
    
    wc.generate(text)  # 根据文本生成词云图
    plt.imshow(wc)  # 显示词云图

     3、不显示坐标轴

    text = 'Keep it simple and stupid.'
    wc = WordCloud(background_color='white', width=500, height=300)  # 实例化词云图对象
    
    wc.generate(text)  # 根据文本生成词云图
    plt.imshow(wc)  # 显示词云图
    plt.axis('off')  # 不显示坐标轴
    plt.show()

     

    环境说明:

     

  • 相关阅读:
    Tomcat:基础安装和使用教程
    java部署
    tomcat 配置访问路径 server.xml配置去掉项目名称 .
    linuxACL控制
    Your PHP installation appears to be missing the MySQL
    ssh报错
    502 Bad Gateway
    单点登录SSO
    tomcat详细介绍
    详解redis5.x版本
  • 原文地址:https://www.cnblogs.com/shanger/p/12990677.html
Copyright © 2011-2022 走看看