先安装 pip install pyecharts
饼图
代码语言:javascript复制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()
词云
代码语言:javascript复制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')