您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 咨询培训 > pyecharts教程
这篇教程简单介绍一下pyecharts(echarts提供给python的接口包)简单使用,感兴趣的可以了解一下。一.安装pyecharts兼容python2.x和python3.x,直接输入安装命令”pipinstallpyecharts”就行。二.使用1.柱状图frompyechartsimportBarbar=Bar(我的第一个图表,这里是副标题)bar.add(服装,[衬衫,羊毛衫,雪纺衫,裤子,高跟鞋,袜子],[5,20,36,10,75,90])bar.render()程序截图:2.水平柱状图frompyechartsimportBarbar=Bar(x轴和y轴交换)attr=[衬衫,羊毛衫,雪纺衫,裤子,高跟鞋,袜子]v1=[5,20,36,10,75,90]v2=[10,25,16,18,55,62]bar.add(商家A,attr,v1)bar.add(商家B,attr,v2,is_convert=True)bar.render()程序截图:3.饼状图frompyechartsimportPiepie=Pie('饼状图')pie.add('',['优秀','良好','及格'],[12,20,3],is_label_show=True)pie.render()程序截图:4.带有涟漪特效动画的散点图frompyechartsimportEffectScatteres=EffectScatter(动态散点图各种图形示例)es.add(,[10],[10],symbol_size=20,effect_scale=3.5,effect_period=3,symbol=pin)es.add(,[20],[20],symbol_size=12,effect_scale=4.5,effect_period=4,symbol=rect)es.add(,[30],[30],symbol_size=30,effect_scale=5.5,effect_period=5,symbol=roundRect)es.add(,[40],[40],symbol_size=10,effect_scale=6.5,effect_brushtype='fill',symbol=diamond)es.add(,[50],[50],symbol_size=16,effect_scale=5.5,effect_period=3,symbol=arrow)es.add(,[60],[60],symbol_size=6,effect_scale=2.5,effect_period=3,symbol=triangle)es.render()程序截图:5.漏斗图frompyechartsimportFunnelattr=[衬衫,羊毛衫,雪纺衫,裤子,高跟鞋,袜子]value=[20,40,60,80,100,120]funnel=Funnel(漏斗图示例)funnel.add(商品,attr,value,is_label_show=True,label_pos=inside,label_text_color=#fff)funnel.render()程序截图:6.仪表盘frompyechartsimportGaugegauge=Gauge(仪表盘示例)gauge.add(业务指标,完成率,66.66)gauge.render()程序截图:7.地理坐标系图程序一:frompyechartsimportGeodata=[(海门,9),(鄂尔多斯,12),(招远,12),(舟山,12),(齐齐哈尔,14),(盐城,15),(赤峰,16),(青岛,18),(乳山,18),(金昌,19),(泉州,21),(莱西,21),(日照,21),(胶南,22),(南通,23),(拉萨,24),(云浮,24),(梅州,25)]geo=Geo(全国主要城市空气质量,datafrompm2.5,title_color=#fff,title_pos=center,width=800,height=600,background_color='#404a59')attr,value=geo.cast(data)geo.add(,attr,value,visual_range=[0,200],visual_text_color=#fff,symbol_size=15,is_visualmap=True)geo.render()程序运行截图:程序二:frompyechartsimportGeodata=[(海门,9),(鄂尔多斯,12),(招远,12),(舟山,12),(齐齐哈尔,14),(盐城,15)]geo=Geo(全国主要城市空气质量,datafrompm2.5,title_color=#fff,title_pos=center,width=800,height=500,background_color='#404a59')attr,value=geo.cast(data)geo.add(,attr,value,type=effectScatter,is_random=True,effect_scale=5)geo.render()程序截图:8.关系图程序一:frompyechartsimportGraphnodes=[{name:结点1,symbolSize:10},{name:结点2,symbolSize:20},{name:结点3,symbolSize:30},{name:结点4,symbolSize:40},{name:结点5,symbolSize:50},{name:结点6,symbolSize:40},{name:结点7,symbolSize:30},{name:结点8,symbolSize:20}]links=[]foriinnodes:forjinnodes:links.append({source:i.get('name'),target:j.get('name')})graph=Graph(关系图-环形布局示例)graph.add(,nodes,links,is_label_show=True,repulsion=8000,layout='circular',label_text_color=None)graph.render()程序截图:9.折线/面积图程序一:frompyechartsimportLineattr=[衬衫,羊毛衫,雪纺衫,裤子,高跟鞋,袜子]v1=[5,20,36,10,10,100]v2=[55,60,16,20,15,80]line=Line(折线图-阶梯图示例)line.add(商家A,attr,v1,is_step=True,is_label_show=True)line.render()程序截图:程序二:frompyechartsimportLineattr=[衬衫,羊毛衫,雪纺衫,裤子,高跟鞋,袜子]v1=[5,20,36,10,10,100]v2=[55,60,16,20,15,80]line=Line(折线图-面积图示例)line.add(商家A,attr,v1,is_fill=True,line_opacity=0.2,area_opacity=0.4,symbol=None)line.add(商家B,attr,v2,is_fill=True,area_color='#000',area_opacity=0.3,is_smooth=True)line.render()程序截图:10.水球图程序一:frompyechartsimportLiquidliquid=Liquid(水球图示例)liquid.add(Liquid,[0.6,0.5,0.4,0.3],is_liquid_outline_show=False)liquid.render()程序截图:程序二:frompyechartsimportLiquidliquid=Liquid(水球图示例)liquid.add(Liquid,[0.6,0.5,0.4,0.3],is_liquid_animation=False,shape='diamond')liquid.render()程序截图:11.地图程序一:frompyechartsimportMapvalue=[155,10,66,78,33,80,190,53,49.6]attr=[福建,山东,北京,上海,甘肃,新疆,河南,广西,西藏]map=Map(Map结合VisualMap示例,width=800,height=600)map.add(,attr,value,maptype='china',is_visualmap=True,visual_text_color='#000')map.render()程序截图:程序二:frompyechartsimportMapvalue=[20,190,253,77,65]attr=['汕头市','汕尾市','揭阳市','阳江市','肇庆市']map=Map(广东地图示例,width=800,height=500)map.add(,attr,value,maptype='广东',is_visualmap=True,visual_text_color='#000')map.render()程序截图:12.平行坐标系frompyechartsimportParallelc_schema=[{dim:0,name:data},{dim:1,name:AQI},{dim:2,name:PM2.5},{dim:3,name:PM10},{dim:4,name:CO},{dim:5,name:NO2},{dim:6,name:CO2},{dim:7,name:等级,type:category,data:['优','良','轻度污染','中度污染','重度污染','严重污染']}]data=[[1,91,45,125,0.82,34,23,良],[2,65,27,78,0.86,45,29,良],[3,83,60,84,1.09,73,27,良],[4,109,81,121,1.28,68,51,轻度污染],[5,106,77,114,1.07,55,51,轻度污染],[6,109,81,121,1.28,68,51,轻度污染],[7,106,77,114,1.07,55,51,轻度污染],[8,89,65,78,0.86,51,26,良],[9,53,33,47,0.64,50,17,良],[10,80,55,80,1.01,75,24,良],[11,117,81,124,1.03,45,24,轻度污染],[12,99,71,142,1.1,62,42,良],[13,95,69,130,1.28,74,50,良],[14,116,87,131,1.47,84,40,轻度污染]]parallel=Parallel(平行坐标系-用户自定义指示器)parallel.config(c_schema=c_schema)parallel.add(parallel,data)parallel.render()程序截图:13.极坐标系图程序一:frompyechartsimportPolarradius=['周一','周二','周三','周四','周五','周六','周日']polar=Polar(极坐标系-堆叠柱状图示例,width=1200,height=600)polar.add(A,[1,2,3,4,3,5,1],radius_data=radius,type='barRadius',is_stack=True)polar.add(B,[2,4,6,1,2,3,1],radius_data=radius,type='barRadius',is_stack=True)polar.add(C,[1,2,3,4,1,2,5],radius_data=radius,type='barRadius',i
本文标题:pyecharts教程
链接地址:https://www.777doc.com/doc-4176225 .html