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

    词云图

    from os import path
    from PIL import Image
    import numpy as np
    import matplotlib.pyplot as plt
    from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
    import jieba
    
    
    text = open(path.join(r'new.txt'),encoding='utf-8').read()
    wordlist = jieba.cut(text, cut_all=True)
    txts = " ".join(wordlist)
    # 这个图片自己选
    coloring = np.array(Image.open(path.join("pic.jpg")))
    # 你可以通过 mask 参数 来设置词云形状
    wc = WordCloud(background_color="white", max_words=2000, mask=coloring,max_font_size=100, random_state=42,font_path='fangsong.ttf')
    wc.generate(txts)
    # create coloring from image
    image_colors = ImageColorGenerator(coloring)
    
    # 在只设置mask的情况下,你将会得到一个拥有图片形状的词云
    plt.imshow(wc, interpolation="bilinear")
    plt.axis("off")
    plt.figure()
    plt.show()

    效果如图:(右边是随便选择的形状)

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  • 相关阅读:
    第12组(78) Beta冲刺 (2/5)(组长)
    第12组 Beta冲刺 (1/6)(组长)
    软工实践个人总结
    第 02 组 每周小结 (3/3)
    第02组 每周小结(2/3)
    第02组 每周小结 (1/3)
    第02组Beta冲刺 总结
    第02组Beta冲刺(5/5)
    第02组Beta冲刺(4/5)
    第02组Beta冲刺(3/5)
  • 原文地址:https://www.cnblogs.com/51python/p/10440534.html
Copyright © 2011-2022 走看看