You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hnu202111020209 e0d4fe3452
1.md
4 years ago
README.md 1.md 4 years ago

README.md

Word

import numpy as np import matplotlib.pyplot as plt import jieba import wordcloud from wordcloud import WordCloud from wordcloud import STOPWORDS import os from os import path from PIL import Image import random

def random_color(word, font_size, position, orientation, font_path, random_state): s = 'hsl(0, %d%%, %d%%)' % (random.randint(20, 40), random.randint(20, 40)) return s path_img = "D:/4.jpg" txt = open("D:/宋词.txt", "r", encoding='utf-8').read() img = Image.open(path_img) mask = np.array(img) text_new = " ".join(jieba.cut(txt)) wc = WordCloud(font_path="C:/Windows/Fonts/stxingka.ttf", mask=mask,mode='RGBA',color_func=random_color ,background_color=None).generate(text_new) #font_path="C:/Windows/Fontsxingka.ttf" #font_path="msyh.ttc" width=24;height=14 plt.figure()
plt.figure(figsize=(width,height)) plt.imshow(wc, interpolation='bilinear') plt.axis('off')