Skip to content

Instantly share code, notes, and snippets.

@Chestermozhao
Created July 30, 2020 08:37
Show Gist options
  • Save Chestermozhao/9e92630aa51e66934f37b92ff6e98c3d to your computer and use it in GitHub Desktop.
Save Chestermozhao/9e92630aa51e66934f37b92ff6e98c3d to your computer and use it in GitHub Desktop.
import os
import matplotlib.pyplot as plt
from imageio import imread
from wordcloud import WordCloud
# font type
base_path = os.getcwd()
font_path = base_path + '/fonts/SourceHanSerif/SourceHanSerifK-Light.otf'
# backgroud image
image_path = base_path + '/bck_img/img_bck.png'
back_coloring = imread(image_path)
def paint_word_cloud():
wordcloud = WordCloud(
font_path=font_path,
background_color="black",
max_words=2000,
mask=back_coloring,
max_font_size=100,
random_state=42,
width=1000,
height=860,
margin=2
).generate_from_frequencies(words_count_dict)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
filename = "wordcloud_imgs/{date}_word_cloud.jpg".format(date=arrow.now().format("YYYY-MM-DD"))
plt.savefig(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment