1Image= Image.open ('f:/__identity/course/Modelling/Jiuzhaigou earthquake/Sichuan map. jpg')2Fig = Plt.figure (figsize= (20, 16))3Graph =Np.array (image)4WC = Wordcloud (font_path='./fonts/simhei.ttf', background_color=' White', mask=graph)#font_path= './fonts/simhei.ttf ' Display Chinese5 #wc.generate (text) # Generate Word cloud, you can enter all the text with generate (Chinese bad word)6Wc.generate_from_frequencies (topworddict)#draw from the already calculated word frequency7Image_color =imagecolorgenerator (graph)8 plt.imshow (WC)9Plt.imshow (Wc.recolor (color_func=image_color))TenPlt.axis ("off") OnePlt.savefig ('f:/__identity/course/Modelling/Jiuzhaigou earthquake/top200wordcloud.png') APlt.show ()
The Chinese problem of word cloud, the key is to add in Wordcloud:
Font_path= './fonts/simhei.ttf '
The Chinese problem of Python word cloud