>>> 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()
网友评论