|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- """
- wordcloud库
- """
- # wordcloud.WordCloud() 注意大小写,只能这么写
- import wordcloud
- c = wordcloud.WordCloud(width=600,height=400,
- min_font_size=50,max_font_size=100,
- font_step=5,
- max_words=20,
- stop_words={'Python'})
- # 这步不是“将 c 定义为 wordcloud 的缩写”,import wordcloud as c才是。这步是设定参数。
- # 括号里如果没填参数,那就用系统默认的。
- # font_step=字体最小间隔;
- # font_path='字体(一般格式为.ttc)';
- # max_words=单词云显示的最大单词数量;
- # stop_words=排除不需要显示的单词列表
-
- print( c.generate('Love and Peace! Love Python! banana, apple or orange. @Python') ) # 向 WordCloud 对象 c 中加载文本txt
- c.to_file('//Users//h//Desktop//picture.png') # 将词云输出为图像文件(.png 或者.jpg)
复制代码
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-26-7a10733b695e> in <module>
11 font_step=5,
12 max_words=20,
---> 13 stop_words={'Python'})
14 # 这步不是“将 c 定义为 wordcloud 的缩写”,import wordcloud as c才是。这步是设定参数。
15 # 括号里如果没填参数,那就用系统默认的。
TypeError: __init__() got an unexpected keyword argument 'stop_words'
stop_words,这怎么会没有呢??
我要做一个词云,想把文本里的Python这个词排除在统计之外
stop_words 参数的下划线去掉,改成 stopwords
- """
- wordcloud库
- """
- # wordcloud.WordCloud() 注意大小写,只能这么写
- import wordcloud
- c = wordcloud.WordCloud(width=600, height=400,
- min_font_size=50, max_font_size=100,
- font_step=5,
- max_words=20,
- stopwords={'Python'})
- # 这步不是“将 c 定义为 wordcloud 的缩写”,import wordcloud as c才是。这步是设定参数。
- # 括号里如果没填参数,那就用系统默认的。
- # font_step=字体最小间隔;
- # font_path='字体(一般格式为.ttc)';
- # max_words=单词云显示的最大单词数量;
- # stop_words=排除不需要显示的单词列表
- print(c.generate('Love and Peace! Love Python! banana, apple or orange. @Python')) # 向 WordCloud 对象 c 中加载文本txt
- c.to_file('//Users//h//Desktop//picture.png') # 将词云输出为图像文件(.png 或者.jpg)
复制代码
|
|