數據分析——pyecharts

導入類庫

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

make_point:標註,相似於matplotlib的texthtml

is_stack:堆疊,將同一圖表中的不一樣圖像堆疊顯示flask

is_label_show:顯示每一個數據的標註網絡

is_datazoom_show:數據縮放顯示echarts

地圖

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')
相關文章
相關標籤/搜索