python的pyecharts(群图乱舞)可视化神器

3 篇文章 0 订阅
2 篇文章 0 订阅

#pyecharts 是Echart和python的一个接口,其中有非常丰富的图
#环境配置 pip install pyecharts==0.5.11
#pip install pyecharts_sanpshot
#pip install echarts countries pypkg(中国地图的包)
1.代码块(使用方法:运行代码,把生成的群图乱舞.html即可)

#time:2019.12.2
#autor:heguobao
#python\pycharm
#Echarts 是百度开源的一个数据可视化 JS 库,pyecharts是一款将python与echarts结合的强大的数据可视化工具(Echarts与Python结合的轮子:pyecharts)
#1.柱状图优势:柱状图利用柱子的高度,反映数据的差异,肉眼对高度差异很敏感
#2 折线图 ,优势:容易反应出数据的走向和变化的趋势
#3.饼图(环图)优势:明确显示数据的比例情况
#4.散点图 优势:对于处理值的分布和数据点的分簇,散点图都很理想。如果数据集中包含非常多的点,那么散点图便是最佳图表
#5.雷达图:了解各数据之间的差异,变动情况和好坏差异
#6.中国地图:了解各省数据的占比
#7.词云图:词云就是文字云,对出现频率比较高的进行显示
from pyecharts import Bar
from pyecharts import Style
from pyecharts import Page
from pyecharts import Line
from pyecharts import Pie
from pyecharts import Scatter
from pyecharts import Radar
from pyecharts import Timeline
from pyecharts import EffectScatter
from pyecharts import Overlap
from pyecharts import Map
from pyecharts import WorldCloud
#环境搭建
#pip install echarts-countries-pypkg
#pip install pyecharts==0.5.11
#pip install pyecharts_sanpshot
def create_charts():
#1。准备所需数据
    page = Page()
    style = Style(height=450,width=1200)
    x1 = [1,2,3,4,5,6,7,8,9,10,11]
    x = ['{}年'.format(i)for i in range(1,12)]
    y = [5,4,7,8,4,8,7,4,7,8,3]
    y1 = [17,15,16,14,18,16,13,17,14,16,19]
#2。将上面的数据套进下面,并对图形的样式和效果进行设置
    bar = Bar('柱形图','单位kg',**style.init_style,background_color=['#6d8346'])
    line = Line()
    line.add('',x,y)
    line.add('',x,y1)
    bar.add('商家A',x,y,mark_line=['average'],mark_point=['min','max'])
    bar.add('商家B',x,y1,mark_line=['average'],mark_point=['min','max'],is_legend_show=True,
            is_datazoom_show=True,datazoom_range=[50,80],xaxis_rotate=45)
    overlap = Overlap(height=450,width=1200)
    overlap.add(bar)
    overlap.add(line)
    page.add(overlap)
#3。
    line = Line('折线图',**style.init_style,background_color='pink')
    es = EffectScatter()
    es.add('',x,y,effect_scale=8)
    es.add('',x,y1,effect_scale=8)

    line.add('商家A',x,y,mark_line=['average'],mark_point=['min','max'])
    line.add('商家B',x,y1,mark_line=['average'],mark_point=['min','max'])
    overlap1 = Overlap(height=450,width=1200)
    overlap1.add(line)
    overlap1.add(es)
    page.add(overlap1)
#4。
    pie_style = {
        "is_label_show": True,
        "radius": [60, 75],
        "rosetype": 'radius'
    }

    pie = Pie('饼图',background_color='green')
    pie1 = Pie('饼图2',background_color='green')
    pie.add('商家A',x,y,mark_line=['average'],mark_point=['min','max'],**pie_style)
    pie1.add('商家B',x,y1,mark_line=['average'],mark_point=['min','max'],**pie_style)
    timeline = Timeline(is_auto_play=True,timeline_bottom=0,height=450,width=1200)
    timeline.add(pie,'')
    timeline.add(pie1,'')
    page.add(timeline)
#5。
    scatter = EffectScatter('散点图',**style.init_style,background_color='pink')
    scatter.add('商家A',x1,y,mark_line=['average'],mark_point=['min','max'])
    scatter.add(('商家B'),x1,y1,mark_line=['average'],mark_point=['min','max'])
    page.add(scatter)

    x3  = [('上海',35),('北京',36),('海南',34),('湖南',31),('广东',39),('惠州',31)]
    y3 = [[20,22,24,28,27,30]]

    y4 = [[21, 22, 23, 25, 29, 20]]
    radar = Radar('雷达图',**style.init_style)
    radar.config(x3)
    radar.add('A',y3)
    radar.add('B',y4)
    page.add(radar)

6#	name = [
        'Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World',
        'Charter Communications', 'Chick Fil A', 'Planet Fitness',
        'Pitch Perfect', 'Express', 'Home', 'Johnny Depp', 'Lena Dunham',
        'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham',
        'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']
    value = [
        10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112,
        965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]
    chart = WordCloud("词云图", **style.init_style)
    chart.add("", name, value, word_size_range=[30, 100], rotate_step=66)
    page.add(chart)

    chart = WordCloud("词云图", **style.init_style)
    chart.add("", name, value, word_size_range=[30, 100], shape='diamond')
    page.add(chart)

#7。
    math = {'河南': 45.23, '北京': 37.56, '河北': 21, '辽宁': 12, '江西': 6, '上海': 20, '安徽': 10, '江苏': 16, '湖南': 9,
            '浙江': 13, '海南': 2, '广东': 22, '湖北': 8, '黑龙江': 11, '澳门': 1, '陕西': 11, '四川': 7,
            '内蒙古': 3, '重庆': 3, '云南': 6, '贵州': 2, '吉林': 3, '山西': 12, '山东': 11, '福建': 4, '青海': 1,
            '天津': 1, '其他': 1}
    a = list(math.keys())
    b = list(math.values())
    map = Map("中国地图", width=1200, height=600)
    map.add("", a, b, maptype='china', is_visualmap=True, is_label_show=True)
    page.add(map)
#7。加入timeline时间线,把几种不一样的图组合在一起,默认为自动播放,左下角有按钮,可以手动停止和手动播放,有自动缩放的柱拉条(可扩大缩放),更多请看图。。。。。。。
    chart = Timeline(is_auto_play=True,timeline_bottom=0,height=450,width=1200)
    chart.add(bar,'第一')
    chart.add(pie,'第二')
    chart.add(pie1,'第三')
    chart.add(line,'第四')
    chart.add(scatter,'第五')
    chart.add(radar,'第六')
    page.add(chart)
    return page
create_charts().render('群图乱舞.html')

2.效果图
A。柱形图和折线图的结合(对其中数据的最大最小,平均值等的显示)
在这里插入图片描述B。折线图和EFFectscatter的结合效果图

在这里插入图片描述C。timeline时间线的设置饼图,默认为自动播放两个图(动态)
在这里插入图片描述
D。散点图(Effectscatter)
在这里插入图片描述E。雷达图
在这里插入图片描述F。中国地图
在这里插入图片描述
G。将全部的图结合在一起并用timeline时间线动态播放(图片无法播放请自己去尝试)

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述3
在这里插入图片描述
。。。。。。。。。。。。。。。。。。。。。。。。。

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值