zoukankan      html  css  js  c++  java
  • 数据分析——pyecharts

    导入类库

    1 from pyecharts import Pie, Bar, Gauge, EffectScatter, WordCloud, Map, Grid, Line, Timeline
    2 import random

    make_point:标注,类似于matplotlib的text

    is_stack:堆叠,将同一图表中的不同图像堆叠显示

    is_label_show:显示每个数据的标注

    is_datazoom_show:数据缩放显示

    地图

    1 value = [120, 110]
    2 attr = [u'河南', u'浙江']
    3 map = Map(u'Map 结合 VisualMap 示例', width=1200, height=600)
    4 map.use_theme('dark')
    5 map.add('', attr, value, maptype=u'china', is_visualmap=True, visual_text_color='#000')
    6 map.render('map.html')

    堆叠柱状图

    1 attr = ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
    2 v1 = [5, 20, 36, 10, 75, 90]
    3 v2 = [10, 25, 8, 60, 20, 80]
    4 bar = Bar('柱状图数据堆叠示例')
    5 bar.add('商家A', attr, v1, mark_point=['average'], is_stack=True)
    6 bar.add('商家B', attr, v2, mark_point=['min', 'max'], is_stack=True)
    7 bar.render('bar.html')

    收缩柱状图

    1 attr = ['{}天'.format(i) for i in range(30)]
    2 v1 = [random.randint(1, 30) for _ in range(30)]
    3 bar = Bar('Bar - datazoom - slider示例')
    4 bar.use_theme('dark')
    5 bar.add('', attr, v1, is_label_show=True, is_datazoom_show=True, is_more_utils=True)
    6 bar.render('bar_slider.html')
    7 # 上面可以通过下面一句链式调用
    8 # (Bar().add().add().render())

    仪表盘

    1 gauge = Gauge('仪表盘示例')
    2 gauge.add('业务指标', '完成率', 66.66)
    3 gauge.render('gauge.html')

    散点图

    1 v1 = [10, 20, 30, 40, 50, 60]
    2 v2 = [25, 20, 15, 10, 60, 33]
    3 es = EffectScatter('动态散点图示例')
    4 es.add('effectScatter', v1, v2)
    5 es.render('effectScatter.html')

    词云

    1 name = [u'网络', u'数据分析.txt', u'hadoop', u'flask']
    2 value = [10000, 6000, 4000, 3000]
    3 wd = WordCloud(width=1300, height=620)
    4 wd.add('', name, value, word_size_range=(20, 100))
    5 wd.render('wordcloud.html')

    饼图

    1 attr = ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高 跟鞋', '袜子']
    2 v1 = [11, 12, 13, 10, 10, 10]
    3 pie = Pie('饼图示例')
    4 # pie.use_theme('dark')
    5 pie.add('服装', attr, v1, is_label_show=True)
    6 pie.render('pie.html')

    网格容器

     1 attr = ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高 跟鞋', '袜子']
     2 v1 = [5, 20, 36, 10, 75, 90]
     3 v2 = [10, 25, 8, 60, 20, 80]
     4 bar = Bar('柱状图示例', height=720)
     5 bar.add('商家A', attr, v1, is_stack=True)
     6 bar.add('商家B', attr, v2, is_stack=True)
     7 line = Line('折线图示例', title_top='50%')
     8 attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
     9 line.add('最高气温',
    10          attr,
    11          [11, 11, 15, 13, 12, 13, 10],
    12          mark_point=['max', 'min'],
    13          mark_line=['average'],
    14          )
    15 line.add('最低气温',
    16          attr,
    17          [1, -2, 2, 5, 3, 2, 0],
    18          mark_point=['max', 'min'],
    19          mark_line=['average'],
    20          legend_top='50%'
    21          )
    22 grid = Grid()
    23 grid.add(bar, grid_bottom='60%')
    24 grid.add(line, grid_top='60%')
    25 grid.render('grid.html')

    时间线

     1 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
     2 pie_1 = Pie("2012 年销量比例", "数据纯属虚构")
     3 pie_1.add("秋季", attr, [random.randint(10, 100) for _ in range(6)],
     4           is_label_show=True, radius=[30, 55], rosetype='radius')
     5 
     6 pie_2 = Pie("2013 年销量比例", "数据纯属虚构")
     7 pie_2.add("秋季", attr, [random.randint(10, 100) for _ in range(6)],
     8           is_label_show=True, radius=[30, 55], rosetype='radius')
     9 
    10 pie_3 = Pie("2014 年销量比例", "数据纯属虚构")
    11 pie_3.add("秋季", attr, [random.randint(10, 100) for _ in range(6)],
    12           is_label_show=True, radius=[30, 55], rosetype='radius')
    13 
    14 pie_4 = Pie("2015 年销量比例", "数据纯属虚构")
    15 pie_4.add("秋季", attr, [random.randint(10, 100) for _ in range(6)],
    16           is_label_show=True, radius=[30, 55], rosetype='radius')
    17 
    18 pie_5 = Pie("2016 年销量比例", "数据纯属虚构")
    19 pie_5.add("秋季", attr, [random.randint(10, 100) for _ in range(6)],
    20           is_label_show=True, radius=[30, 55], rosetype='radius')
    21 
    22 timeline = Timeline(is_auto_play=True, timeline_bottom=0)
    23 timeline.use_theme('dark')
    24 timeline.add(pie_1, '2012 年')
    25 timeline.add(pie_2, '2013 年')
    26 timeline.add(pie_3, '2014 年')
    27 timeline.add(pie_4, '2015 年')
    28 timeline.add(pie_5, '2016 年')
    29 timeline.render('timeline.html')
  • 相关阅读:
    949. Largest Time for Given Digits
    450. Delete Node in a BST
    983. Minimum Cost For Tickets
    16. 3Sum Closest java solutions
    73. Set Matrix Zeroes java solutions
    347. Top K Frequent Elements java solutions
    215. Kth Largest Element in an Array java solutions
    75. Sort Colors java solutions
    38. Count and Say java solutions
    371. Sum of Two Integers java solutions
  • 原文地址:https://www.cnblogs.com/siplips/p/9853205.html
Copyright © 2011-2022 走看看