Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
e0d4fe3452 | 4 years ago |
@ -1,2 +1,28 @@
|
||||
# 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')
|
||||
|
||||
Loading…
Reference in new issue