简单的词云制作和动态数据分析图表

2018-09-19  本文已影响0人  Py_Explorer

1、安装库:

pip install pyecharts

2、词云:

shape参数用来调整词云形状,

word_size_ragne限定字体大小范围,更多参数请参考API

os.system可以直接程序运行时候打开生成的html网页

#coding=utf-8
import os
from pyecharts import WordCloud

def worldcloud(x, y, label):
    worldcloud = WordCloud(width=1300, height=620)
    worldcloud.add("", x, y, word_size_range=[20, 100], shape="triangle-forward")
    worldcloud.render()
    os.system(r"render.html")
#x 为需要制作词云所需的词组
x = [
"免费学python", "爬虫", "人工智能", "大数据", "Django", "Flask",
"机器学习", "数据分析", "深度学习", "运维测试", "TensorFlow"
]
#y为对应的词组的大小
y = [
10000, 6181, 4386, 4055, 2467, 1234, 5678, 1111, 2222, 3333, 4444
]
label = '词云'
worldcloud(x, y, label)

3、统计图表(饼状图,条形图,折线图):

shape参数用来调整词云形状('circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star')

word_size_ragne限定字体大小范围,更多参数请参考API

采用百度echarts图表绘制库,漂亮美观,是对matplotlib的强有力补充

#coding=utf-8
import os
from pyecharts import Bar, Pie, Line

def get_charts(x, y, label, type):
    if type == 1:
        c = Pie("饼状图")
    elif type == 2:
        c = Bar("条形图")
    elif type == 3:
        c = Line("折线图")
    c.add(label, x, y, is_more_utils=True)
    c.show_config()
    c.render()
    os.system(r"render.html")
#需要的数据
x = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
#需要的数据量
y = [5, 20, 36, 10, 75, 90]
label = "服装"
type = 3

get_charts(x, y, label, type)
上一篇下一篇

猜你喜欢

热点阅读