2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > python代码生成词云图

python代码生成词云图

时间:2020-09-08 16:57:03

相关推荐

python代码生成词云图

注意要下载对应版本的pyecharts==0.5.11

# pip uninstall pyechartspip install pyecharts==0.5.11

方法一:

import pandas as pdimport jiebafrom collections import Counterfrom pyecharts import WordCloudimport random# 函数接口def simple_word_cloud(mylist, width, height, size_range, shape, target_html):cloud_data = [word for word in mylist]count = Counter(cloud_data)wordcloud = WordCloud(width=1300, height=620)wordcloud.add('', count.keys(), count.values(), word_size_range=[10, 100], shape='circle', rotate_step=30)wordcloud.render(target_html)# 模拟读取csv中的某一列数据# 生成:这里以生成dataframe为例lists = ["大数据技术","HTML5","JQuery","JavaScript","css","MapReduce","Storm","AI","LSP","NLP","AlphaGo","Hadoop","Spark","Hive","NoSQL","Pig",'大数据','数据科学','python','人工智能',"Java","c","c++","c#","Go","css"] for i in range(random.randint(100,1000)): lists.append(random.choice(lists)) my_dict = {'测试用例':lists}df = pd.DataFrame(my_dict)# 读取:直接输入list集合my_list = list(df['测试用例'])# 参数传递width=1200height=600size_range=[10,100]shape = 'circle'target_html = "./wordcloud.html" #simple_word_cloud(my_list,width,height,size_range,shape,target_html)

效果

方法二:

def getWordCloud(filters):wc = wordcloud.WordCloud(font_path = "simkai.ttf",#指定字体类型background_color = "white",#指定背景颜色max_words = 200, # 词云显示的最大词数max_font_size = 200)#指定最大字号#mask = mask) #指定模板,可以是图片word_clean=" ".join(filters)wc = wc.generate(word_clean)##生成词云plt.imshow(wc)plt.axis("off")plt.show()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。