本文整理汇总了Python中wordcloud.STOPWORDS.update方法的典型用法代码示例。如果您正苦于以下问题:Python STOPWORDS.update方法的具体用法?Python STOPWORDS.update怎么用?Python STOPWORDS.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wordcloud.STOPWORDS
的用法示例。
在下文中一共展示了STOPWORDS.update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WordCloud
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import update [as 别名]
#return "hsl(%d, %d%%, %d%%)" % (H, S, B)
if rv == 0:
return "hsl(179, 96%, 55%)"
elif rv == 1:
return "hsl(187, 99%, 56%)"
elif rv == 2 :
return "hsl(174, 100%, 66%)"
elif rv == 3:
return "hsl(176, 99%, 76%)"
else :
return "hsl(63, 22%, 95%)"
#return "hsl(%d, 80%%, 50%%)" % random_state.randint(0, 255)
wc = WordCloud(background_color="white", max_words=2000, mask=alice_mask,
stopwords=STOPWORDS.update(wordToRemove), color_func=maria_color_fun,
min_font_size=8)
print("going to generate the cloud")
# generate word cloud
wc.generate(text)
print(wc.max_words)
# store to file
wc.to_file(path.join(d, OUTPUTFILE))
# show
plt.imshow(wc)
#plt.axis("off")
#plt.figure()
#plt.imshow(alice_mask, cmap=plt.cm.gray)
plt.axis("off")
示例2: cloudyscience
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import update [as 别名]
def cloudyscience(idnames):
# colormap version
def cmap_color_func(word, font_size, position, orientation,alph,random_state):
colr = cm.jet(random.randint(0, 255))
colr2 = colorsys.rgb_to_hsv(colr[0],colr[1],colr[2])
sat = "70%"
var = "%s" % alph +"%"
return "hsl(%d, %s, %s)" % (int(float(colr2[0])*255),sat,var)
stp = ['1','2','3','4','5','6','7','8','9','0','10','et','al',
'a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z']
# Shuffle randomly
random.shuffle(idnames)
papernum = len(idnames)
print 'PROCESSING PAPERS...'
for idname in idnames:
print idname
# Make temp file
os.system('rm -rf temp')
os.system('mkdir temp')
######## Wordle post ########
pdfpath = 'http://arxiv.org/pdf/'+idname
out = open('temp/test.pdf','w')
print "Downloading paper..."
out.write(urllib.urlopen(pdfpath).read())
out.flush()
# Convert the PDF to text
print "Processing..."
os.system('pdftotext temp/test.pdf > temp/test.txt')
# Turn into a Wordle
text = open('temp/test.txt').read()
outname = '%s_wordle.png' % idname
# Initalise wordcloud
wc = WordCloud(stopwords=STOPWORDS.update(stp),width=500,height=500,prefer_horizontal=0.95,scale=1,color_func=cmap_color_func,font_path='DensiaSans.otf')
# Check text
if len(text) > 0:
wc.generate(text)
else:
print 'PDF text corrupted... skipping this paper'
continue
imshow(wc)
axis("off")
wc.to_file(outname)
return
示例3: any
# 需要导入模块: from wordcloud import STOPWORDS [as 别名]
# 或者: from wordcloud.STOPWORDS import update [as 别名]
coff_rev = [i for i in test if any(w in i[u'reviewText'].lower() for w in wanted)]
coff_rev_ex = [i for i in coff_rev if not any(w in i[u'reviewText'].lower() for w in unwanted)]
coff_rev_espre = [i for i in coff_rev_ex if any(w in i[u'reviewText'].lower() for w in esprewanted)]
## review to text
def revew2revtext(rev_data):
output_text = ''
for i in range(len(rev_data)):
rev = rev_data[i]['reviewText']
rev = str(rev)
output_text = output_text + rev
return output_text
coff_rev_espre_text= revew2revtext(coff_rev_espre)
## word cloud plot
from os import path
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
text = coff_rev_espre_text
wordcloud = WordCloud(font_path='/Library/Fonts/AppleSDGothicNeo-ExtraBold.otf',width=800, height=800,stopwords=STOPWORDS.update(["buy","use", "reviewerID", "helpful"])).generate(text)
plt.imshow(wordcloud)
plt.axis("off")
plt.savefig('test2.png')
plt.show()