import matplotlib.pyplot as plt
import jieba
from wordcloud import wordcloud
# 1. Read the words
text = open('text/test.txt', 'r', encoding='utf-8').read()
print(text)
# 2. Cut lyrics
cut_text = jieba.cut(text)
# print(type(cut_text))
# print(next(cut_text))
# print(next(cut_text))
# 3. stitching together a space
result = " ".join(cut_text)
# print(result)
# 4. Generate word cloud
wc = wordcloud.WordCloud(
font_path = 'font / Wang Hanzong survey kiosk flow fan .ttf', # Font Road King
background_color = 'white', # Background color
width=1000,
height=600,
max_font_size = 50, # font size
min_font_size=10,
mask = plt.imread ( 'images / xin.jpg'), # background image
max_words=1000
)
wc.generate(result)
wc.to_file ( 'images / jielun.png') # Save the picture
# 5. Display picture
plt.figure ( 'images / jielun') name # picture shows
plt.imshow(wc)
plt.axis ( 'off') # coordinate Close
plt.show()
font in the font just introduced a font into the like, plt.imread the pictures that you want the last word cloud shape chalk according to which, I choose here was a cloud photo, test.txt is that some words in content
Outgoing kind cheerful and lively, light-hearted humor and sincere enthusiasm amiable steady open-minded forthright candid mature independence Decisive talkative astute deep strong enthusiasm excitement funny frank and friendly quiet perseverance cautious loyalty friendly serious faithful Optimistic self-confidence frank courageous calm perseverance tolerate considerate contented meet interesting positive and pragmatic hard-working gas fearless Frivolous impulse childish selfish ego worships money and rely on self-willed stubborn temper hypocrisy withdrawn mean arbitrary Impetuous reckless irritability irritability suspicious rash mercurial cunning lazy imperious stubborn suspicion provocative indifference Vanity cold repeatedly domineering ego rebellious resentment reckless indulgence poor stubborn Introverted shy and sensitive fragile self-esteem slow weak cowering submissive timid man of quiet conservatism passive tolerance Mild depression cautious timidity honest peace implicit obedience to accommodate shy coy slow tedious rambling Slow wordy patience pessimistic delay irritability compromise nagging Sociable organization has good toughness can rely on the normal form good-natured and sociable without objection competitive respected self-control Re-order incentive methodical listener unrestrained popular leader Neurotic idiot inert excitable good criticism does not focus quarrelsome aimless do not forgive easily agitated without enthusiasm Difficult to predict alienation are not flexible hi loud emotional manipulation rule compulsive desire good performance Adaptability work efficiently overcome the difficulties conscientious and careful adherence to good order and organized others to understand the often trivial emotional Perfectionist rash is not practical and easy inconstant easy to hasty decisions languages slow movement is not easy to expose inner life Stubbornly inflexible poor ability to adapt not appear tends to stand sleek sophisticated communicative talkative
FIG effect as