The color palette from the R package worldcloud2 is very awesome. But it has some bugs. I can not set the mask for the world cloud. In python, this package is much user-friendly.
To be notice, the mask picture is very important. You can only use the rgb format. The picture has “0, 0, 0” for the background, “255, 255, 255” for the background. rgbi format is not supported even if it is very similar to rgb.
from os import path from PIL import Image import numpy as np import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
## Read the whole text. text = open('tmp.txt').read()
## read the mask image ## taken from ## http://www.stencilry.org/stencils/movies/alice%20in%20wonderland/255fk.jpg alice_mask = np.array(Image.open("/home/ken/Downloads/cloud.png"))