From 3593705de68c585e69d877abf213ff183f031cf7 Mon Sep 17 00:00:00 2001 From: peyxgo6zl <1506421526@qq.com> Date: Tue, 10 May 2022 16:19:58 +0800 Subject: [PATCH] ADD file via upload --- word.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 word.py diff --git a/word.py b/word.py new file mode 100644 index 0000000..50da256 --- /dev/null +++ b/word.py @@ -0,0 +1,39 @@ +import jieba +from matplotlib import pyplot as plt +from wordcloud import WordCloud +from PIL import Image +import numpy as np +import sqlite3 + +def makeWordcloud(image_name): + con = sqlite3.connect('data.db') + cur = con.cursor() + sql = 'select info from movie250 ' + data = cur.execute(sql) + text = "" + for item in data: + text = text + item[0] + cur.close() + con.close() + cut = jieba.cut(text) + string = ' '.join(cut) + img = Image.open(image_name) + img_array = np.array(img) + wc = WordCloud( + # background_color = 'white', + # mask = img_array, + # font_path = 'simsun.ttc' + font_path="msyhbd.ttc", + mask=img_array, + width=1500, + height=1000, + background_color="white", + min_font_size=5, + max_font_size=120, + max_words=600 + ) + wc.generate_from_text(string) + fig = plt.figure(1) + plt.imshow(wc) + plt.axis('off') + plt.savefig('output.jpg', dpi=1600) \ No newline at end of file