先安装 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()

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

词云

jieba分词
【数据分析可视化】饼图、词云_存到文件_03
【数据分析可视化】饼图、词云_其他_04

# -*- 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')

【数据分析可视化】饼图、词云_存到文件_05