Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
keeleliin
word_cloud_est
Commits
b8039845
Commit
b8039845
authored
Apr 29, 2015
by
Andreas Mueller
Browse files
add (not that great) example using alice
parent
d9206a41
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/alice_colored.png
0 → 100644
View file @
b8039845
210 KB
examples/colored.py
0 → 100755
View file @
b8039845
#!/usr/bin/env python2
"""
Masked wordcloud
================
Using a mask you can generate wordclouds in arbitrary shapes.
"""
from
os
import
path
from
scipy.misc
import
imread
import
matplotlib.pyplot
as
plt
from
wordcloud
import
WordCloud
,
STOPWORDS
from
wordcloud.color_from_image
import
ImageColorGenerator
d
=
path
.
dirname
(
__file__
)
# Read the whole text.
text
=
open
(
path
.
join
(
d
,
'alice.txt'
)).
read
()
# read the mask / color image
alice_coloring
=
imread
(
path
.
join
(
d
,
"alice_color.png"
))
wc
=
WordCloud
(
background_color
=
"white"
,
max_words
=
2000
,
mask
=
alice_coloring
,
stopwords
=
STOPWORDS
.
add
(
"said"
),
max_font_size
=
40
,
random_state
=
42
)
# generate word cloud
wc
.
generate
(
text
)
# create coloring from image
image_colors
=
ImageColorGenerator
(
alice_coloring
)
# show
plt
.
imshow
(
wc
)
plt
.
title
(
"original"
)
plt
.
axis
(
"off"
)
plt
.
figure
()
# recolor wordcloud and show
# we could also give color_func=image_colors directly in the constructor
plt
.
imshow
(
wc
.
recolor
(
color_func
=
image_colors
))
plt
.
title
(
"recolored"
)
plt
.
axis
(
"off"
)
plt
.
figure
()
plt
.
imshow
(
alice_coloring
,
cmap
=
plt
.
cm
.
gray
)
plt
.
axis
(
"off"
)
plt
.
show
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment