Skip to content

Instantly share code, notes, and snippets.

@mlai-demo
Created August 11, 2019 22:49
Show Gist options
  • Save mlai-demo/53de2d2cb8545e1603d8fe7c454a22af to your computer and use it in GitHub Desktop.
Save mlai-demo/53de2d2cb8545e1603d8fe7c454a22af to your computer and use it in GitHub Desktop.
import numpy as np
from PIL import Image
roman_mask = np.array(Image.open(path.join(d, 'roman7.png')))
text_stem = open(fpath + '/Plutarch_stem.txt', 'rt').read()
wc = WordCloud(stopwords=stop_words,
max_font_size=200,
width=5000,
height=4000,
background_color="white",
max_words=4000,
mask=roman_mask,
contour_width=3,
contour_color='steelblue',
random_state = 64).generate(text_stem)
wc.to_file(path.join(d, "wc_stemmed.png")) #comment out if no need to store the png
fig = plt.figure().set_size_inches(18, 18)
plt.imshow(wc, interpolation='bilinear')
plt.axis("off")
plt.title("Plutarch's Lives (Stemmed)", fontsize= 20)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment