数据展示:
- # 展示饼图
- def showPie(self, title, attr, value):
- from pyecharts import Pie
- pie = Pie(title)
- pie.add("aa", attr, value, is_label_show=True)
- pie.render()
-
- # 展示矩形树图
- def showTreeMap(self, title, data):
- from pyecharts import TreeMap
- data = data
- treemap = TreeMap(title, width=1200, height=600)
- treemap.add("深圳", data, is_label_show=True, label_pos='inside', label_text_size=19)
- treemap.render()
-
- # 展示条形图
- def showLine(self, title, attr, value):
- from pyecharts import Bar
- bar = Bar(title)
- bar.add("深圳", attr, value, is_convert=False, is_label_show=True, label_text_size=18, is_random=True,
- # xaxis_interval=0, xaxis_label_textsize=9,
- legend_text_size=18, label_text_color=["#000"])
- bar.render()
-
- # 展示词云
- def showWorkCloud(self, content, image_filename, font_filename, out_filename):
- d = path.dirname(__name__)
- # content = open(path.join(d, filename), 'rb').read()
- # 基于TF-IDF算法的关键字抽取, topK返回频率最高的几项, 默认值为20, withWeight
- # 为是否返回关键字的权重
- tags = jieba.analyse.extract_tags(content, topK=100, withWeight=False)
- text = " ".join(tags)
- # 需要显示的背景图片
- img = imread(path.join(d, image_filename))
- # 指定中文字体, 不然会乱码的
- wc = WordCloud(font_path=font_filename,
- background_color='black',
- # 词云形状,
- mask=img,
- # 允许最大词汇
- max_words=400,
- # 最大号字体,如果不指定则为图像高度
- max_font_size=100,
- # 画布宽度和高度,如果设置了msak则不会生效
- # width=600,
- # height=400,
- margin=2,
- # 词语水平摆放的频率,默认为0.9.即竖直摆放的频率为0.1
- prefer_horizontal=0.9
- )
- wc.generate(text)
- img_color = ImageColorGenerator(img)
- plt.imshow(wc.recolor(color_func=img_color))
- plt.axis("off")
- plt.show()
- wc.to_file(path.join(d, out_filename))
-
- # 展示 pyecharts 的词云
- def showPyechartsWordCloud(self, attr, value):
- from pyecharts import WordCloud
- wordcloud = WordCloud(width=1300, height=620)
- wordcloud.add("", attr, value, word_size_range=[20, 100])
- wordcloud.render()
后记
(编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|