园长

学无止境 知行合一

2021年7月24日

项目涵盖:

  • Python中urllib、sqlite3、bs4、re等
  • Flask库
  • EChart
  • wordcloud
  • highlight.js
  • …..

项目地址:https://github.com/yzyyz1387/flask-visualData-practice (网页来源于网络源码,做了部分修改)

访问地址(或因博客更新不及时导致无法访问):http://vd.yzyyz.top/

ECHARTS

运用ECharts可对手中的数据进行可视化,详见其官网:https://echarts.apache.org/zh/index.html,可根据文档进行使用。以下是一个例子:

WordCloud

我的需求较为简单,这里不做赘述,WordCloud:http://amueller.github.io/word_cloud/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from wordcloud import WordCloud  #词云
import jieba #分词
from matplotlib import pyplot as plt #绘图 数据可视化
from PIL import Image #图像处理
import numpy as np
import sqlite3


#连接数据库获取数据
conn = sqlite3.connect('movie.db')
cur= conn.cursor()
sql ='''
select dec from movie250
'''
data=cur.execute(sql)
text=""
for item in data:
text = text+item[0]
cur.close()
conn.close()

# 分词
cut = jieba.cut(text)
string=" ".join(cut)
print(len(string))

#绘图遮罩配置等
img=Image.open(r'.\static\asstes\test.jpg')
imgarray=np.array(img)
wc=WordCloud(
background_color='#ffffff',
mask=imgarray,
font_path="msyh.ttc",
)
wc.generate_from_text(string)

#绘制
fig=plt.figure(1)
plt.imshow(wc)
plt.axis('off') #是否显示坐标轴
# plt.show()
wc.to_file('static/asstes/word.jpg') #保存图片


 评论




博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议

本站使用 volantis 作为主题 。