• 01 词云实例


    练习:将一段文字生成词云

    实现:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # author:albert time:2019/10/28
    from wordcloud import WordCloud
    import matplotlib.pyplot as plt
    
    txt = "life is short,you need python.
    中国,是以华夏文明为源泉、中华文化为基础,并以汉族为主体民族的多民族国家,通用汉语、汉字,
    汉族与少数民族被统称为“中华民族”,又自称为炎黄子孙、龙的传人。中国是世界四大文明古国之一,有着悠久的历史,距今约5000年前,
    以中原地区为中心开始出现聚落组织进而形成国家,后历经多次民族交融和朝代更迭,直至形成多民族国家的大一统局面。
    20世纪初辛亥革命后,君主政体退出历史舞台,共和政体建立。1949年中华人民共和国成立后,在中国大陆建立了人民代表大会制度的政体。"
    
    wc = WordCloud(
        width=1000,         # 词云的宽度
        height=800,         # 词云的高度
        background_color='white',       #词云背景色
        font_path="C:WindowsFontssimkai.ttf", # 该路径是个人电脑中的字体的文件地址,一般默认在该文件中
    )
    
    wc.generate(txt)        # 将txt中的内容生成词云
    wc.to_file("wc.png")    # 将词云输出文件设置为图片
    
    plt.imshow(wc)      # 显示词云文件
    plt.show()

    实现效果:

    词云效果

     

    问题:文本中存在[is]和[you],这两个单词没有显示,如何设置显示在图片中?

  • 相关阅读:
    Leetcode Plus One
    Leetcode Swap Nodes in Pairs
    Leetcode Remove Nth Node From End of List
    leetcode Remove Duplicates from Sorted Array
    leetcode Remove Element
    leetcode Container With Most Water
    leetcode String to Integer (atoi)
    leetcode Palindrome Number
    leetcode Roman to Integer
    leetcode ZigZag Conversion
  • 原文地址:https://www.cnblogs.com/xiaodan1040/p/11755501.html
Copyright © 2020-2023  润新知