一、Echarts
1 下载.js文件,可以在官网进行定制:echarts.apache.org/zh/builder.…
2 直接在官网学习如何制作图表:echarts.apache.org/examples/zh…
3 直接快速上手:echarts.apache.org/zh/tutorial…
4 使用方法:可以直接在官网更改后拿来用,不懂得直接在文档左侧直接粘贴搜索配置项,则可以看到详细的配置信息
5 在设置横坐标一般从数据库查出来是字符串,则在页面上渲染的时候,在js的option设置里 面,不能直接打印出来,需要转一下json。
xAxis:{
type:''
data: {{ data | tojson }}
}
二、 WordCloud
1 官方网站
amueller.github.io/word_cloud/…
2 python各种外部库下载地址
CTRL+F直接查找wordcloud 库,点开,然后一定要注意选择适合自己python版本的下载,**注意:电脑是64位的,但是python可能是32位的,需要下载32位的。 **
** 然后在文件的位置:运行 ** pip install wordcloud-1.8.1-cp36-cp36m-win32.whl
3 导入包
#分词
from jieba
#绘图,数据可视化
from matplotlib import pyplot as plt
#词云
from wordcloud import WordCloud
#图片处理
from PIL import Image
#矩阵运算
import numpy as np
4 开始使用
# 分词
import jieba
# 绘图,数据可视化
from matplotlib import pyplot as plt
# 词云
from wordcloud import WordCloud
# 图片处理
from PIL import Image
# 矩阵运算
import numpy as np
# 先从数据库拿数据
from pymongo import MongoClient
# 连接服务器
conn = MongoClient("localhost", 27017)
# 连接数据库
db = conn.mydb
# 获取集合
collection = db.student
# 进行取数据NOSQL
# “info”:1 :查询info字段的所有值("info":0 :则除了info字段都显示),_id:0不显示id值
res = collection.find({},{"info":1,'_id':0})
# res = str(res)
# 将所有的文字连接起来
text = ''
for item in res:
text = text + item['info']
# print(text)
# 关闭连接
conn.close()
# 对拿到的数据进行分词
cut = jieba.cut(text)
string = ' '.join(cut) # ‘’中间记得加空格
# print(string) # 打印分了多少词
# print(len(string))
# 图片处理
img = Image.open('static/images/tree.jpg')
# 将图片转换为数组
img_array = np.array(img)
# 封装对象
wc =WordCloud(
background_color='white', # 设置背景颜色
mask=img_array, # 设置遮罩
font_path="msyh.ttc" # 字体所在位置:C:\Windows\Fonts,进入属性,然后复制名字)
# 加载数据
wc.generate_from_text(string)
# 绘制图片
fig = plt.figure(1) # 1:找第一个位置
plt.imshow(wc) # 按照wc的规则,显示图片
plt.axis('off') # 是否显示坐标轴
# plt.show() #要生成到图片,一定要把这里注释掉
# 输出词云图片到文件
plt.savefig(r'.\static\test\word.jpg',dpi=800) # dpi: 可选, 清晰度