美文网首页
简单的词云制作和动态数据分析图表

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

作者: Py_Explorer | 来源:发表于2018-09-19 14:58 被阅读0次

    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)

    相关文章

      网友评论

          本文标题:简单的词云制作和动态数据分析图表

          本文链接:https://www.haomeiwen.com/subject/rejinftx.html