【数据分析可视化】饼图、词云

先安装 pip install pyecharts

饼图

在这里插入图片描述


from pyecharts import options as opts
from pyecharts.charts import Pie
L1 = ['教授','副教授','讲师','助教','其他']
num = [20,30,10,12,8]
c = Pie()
c.add("",[list(z) for z in zip(L1,num)])
c.set_global_opts(title_opts=opts.TitleOpts(title = "Pie"))
c.render_notebook()

在这里插入图片描述

词云

jieba分词
在这里插入图片描述
在这里插入图片描述

# -*- coding: utf-8 -*-
from wordcloud import WordCloud
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import jieba
 
# 打开文本
text = open('xyj.txt').read()
 
# 中文分词
text = ' '.join(jieba.cut(text))
print(text[:100])
 
# 生成对象
mask = np.array(Image.open("black_mask.png"))
wc = WordCloud(mask=mask, font_path='Hiragino.ttf', mode='RGBA', background_color=None).generate(text)
 
# 显示词云
plt.imshow(wc, interpolation='bilinear')
plt.axis("off")
plt.show()
 
# 保存到文件
wc.to_file('wordcloud4.png')

在这里插入图片描述

原创文章 257 获赞 187 访问量 16万+

猜你喜欢

转载自blog.csdn.net/weixin_43469680/article/details/105861272
今日推荐