美文网首页
2019-12-31生成简单词云

2019-12-31生成简单词云

作者: 小鱼儿spr | 来源:发表于2019-12-31 11:56 被阅读0次
>>> import string
>>> from wordcloud import WordCloud
>>> import matplotlib.pyplot as plt
>>> wc=WordCloud(background_color='white',max_words=2000,
font_path='C:\Windows\Fonts\微软雅黑\msyh.ttc',height= 1200,width=1600,max_font_size=100,random_state=30,)
>>> wc
<wordcloud.wordcloud.WordCloud object at 0x000000000ED435C0>
>>> myword=wc.generate(se)
plt.i
>>> plt.imshow(myword)
<matplotlib.image.AxesImage object at 0x0000000014961898>
>>> plt.axis("off")
(-0.5, 1599.5, 1199.5, -0.5)
>>> plt.show()

可以添加背景图片哦

import numpy as np
bkimage = np.array(Image.open("e:/pic.jpg")) #添加背景图片
ic = ImageColorGenerator(bkimage)
wc=WordCloud(
    font_path = "C:\Windows\Fonts\微软雅黑\msyh.ttc",height= 1200,width=1600,max_font_size=100,random_state=30,mask = bkimage).generate(text)
plt.imshow(wc.recolor(color_func=ic),interpolation ='bilinear')
plt.show()



相关文章

网友评论

      本文标题:2019-12-31生成简单词云

      本文链接:https://www.haomeiwen.com/subject/zheboctx.html