admin 管理员组文章数量: 1086019
2024年1月11日发(作者:java常用工具类下载)
这篇教程简单介绍一下pyecharts(echarts提供给python的接口包)简单使用,感兴趣的可以了解一下。
一.安装
pyecharts兼容和,直接输入安装命令”pip install pyecharts”就行。
二.使用
1. 柱状图
from pyecharts import Bar
bar =Bar("我的第一个图表", "这里是副标题")
("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20,
36, 10, 75, 90])
()
程序截图:
2. 水平柱状图
from pyecharts import Bar
bar =Bar("x 轴和 y 轴交换")
attr=["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1=[5, 20, 36, 10, 75, 90]
v2=[10, 25, 16, 18, 55, 62]
("商家A", attr, v1)
("商家B", attr, v2, is_convert=True)
()
程序截图:
3. 饼状图
from pyecharts import Pie
pie=Pie('饼状图')
('',['优秀','良好','及格'],[12,20,3],is_label_show=True)
()
程序截图:
4. 带有涟漪特效动画的散点图
from pyecharts import EffectScatter
es =EffectScatter("动态散点图各种图形示例")
("", [10], [10], symbol_size=20, effect_scale=, effect_period=3,
symbol="pin")
("", [20], [20], symbol_size=12, effect_scale=,
effect_period=4,symbol="rect")
("", [30], [30], symbol_size=30, effect_scale=,
effect_period=5,symbol="roundRect")
("", [40], [40], symbol_size=10, effect_scale=,
effect_brushtype='fill',symbol="diamond")
("", [50], [50], symbol_size=16, effect_scale=,
effect_period=3,symbol="arrow")
("", [60], [60], symbol_size=6, effect_scale=,
effect_period=3,symbol="triangle")
()
程序截图:
5. 漏斗图
from pyecharts import Funnel
attr =["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
value =[20, 40, 60, 80, 100, 120]
funnel =Funnel("漏斗图示例")
("商品", attr, value, is_label_show=True, label_pos="inside",
label_text_color="#fff")
()
程序截图:
6. 仪表盘
from pyecharts import Gauge
gauge =Gauge("仪表盘示例")
("业务指标", "完成率",
()
程序截图:
7. 地理坐标系图
程序一:
from pyecharts import Geo
data =[ ("海门", 9),("鄂尔多斯", 12),("招远", 12),("舟山", 12),("齐齐哈尔", 14),("盐城", 15), ("赤峰", 16),("青岛", 18),
("乳山", 18),("金昌", 19),("泉州", 21),("莱西", 21), ("日照",
21),("胶南", 22),("南通", 23),("拉萨", 24),("云浮", 24),("梅州", 25)]
geo =Geo("全国主要城市空气质量", "data from ", title_color="#fff",
title_pos="center",width=800, height=600, background_color='#404a59')
attr, value =(data)
("", attr, value, visual_range=[0, 200], visual_text_color="#fff",
symbol_size=15, is_visualmap=True)
()
程序运行截图:
程序二:
from pyecharts import Geo
data =[("海门", 9), ("鄂尔多斯", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15)]
geo =Geo("全国主要城市空气质量", "data from ", title_color="#fff",
title_pos="center", width=800, height=500, background_color='#404a59')
attr, value =(data)
("", attr, value, type="effectScatter", is_random=True, effect_scale=5)
()
程序截图:
8. 关系图
程序一:
from pyecharts import Graph
nodes =[{"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 =[]
for i in nodes:
for j in nodes:
({"source": ('name'), "target": ('name')})
graph =Graph("关系图-环形布局示例")
("", nodes, links, is_label_show=True, repulsion=8000,
layout='circular', label_text_color=None)
()
程序截图:
9. 折线/面积图
程序一:
from pyecharts import Line
attr =["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 =[5, 20, 36, 10, 10, 100]
v2 =[55, 60, 16, 20, 15, 80]
line =Line("折线图-阶梯图示例")
("商家A", attr, v1, is_step=True, is_label_show=True)
()
程序截图:
程序二:
from pyecharts import Line
attr =["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 =[5, 20, 36, 10, 10, 100]
v2 =[55, 60, 16, 20, 15, 80]
line =Line("折线图-面积图示例")
("商家A", attr, v1, is_fill=True, line_opacity=, area_opacity=,
symbol=None)
("商家B", attr, v2, is_fill=True, area_color='#000', area_opacity=,
is_smooth=True)
()
程序截图:
10. 水球图
程序一:
from pyecharts import Liquid
liquid =Liquid("水球图示例")
("Liquid", [, , , ], is_liquid_outline_show=False)
()
程序截图:
程序二:
from pyecharts import Liquid
liquid =Liquid("水球图示例")
("Liquid", [, , , ], is_liquid_animation=False, shape='diamond')
()
程序截图:
11. 地图
程序一:
from pyecharts import Map
value =[155, 10, 66, 78, 33, 80, 190, 53, ]
attr =["福建", "山东", "北京", "上海", "甘肃", "新疆", "河南", "广西", "西藏"]
map=Map("Map 结合 VisualMap 示例", width=800, height=600)
("", attr, value, maptype='china', is_visualmap=True,
visual_text_color='#000')
()
程序截图:
程序二:
from pyecharts import Map
value =[20, 190, 253, 77, 65]
attr =['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市']
map=Map("广东地图示例", width=800, height=500)
("", attr, value, maptype='广东', is_visualmap=True,
visual_text_color='#000')
()
程序截图:
12. 平行坐标系
from pyecharts import Parallel
c_schema =[ {"dim": 0, "name": "data"}, {"dim": 1, "name": "AQI"}, {"dim":
2, "name": ""}, {"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, , 34, 23, "良"], [2, 65, 27, 78, , 45, 29, "良"], [3, 83, 60, 84, , 73, 27, "良"], [4, 109, 81, 121, , 68, 51, "轻度污染"],
[5, 106, 77, 114, , 55, 51, "轻度污染"], [6, 109, 81, 121, , 68,
51, "轻度污染"], [7, 106, 77, 114, , 55, 51, "轻度污染"], [8, 89, 65, 78, ,
51, 26, "良"],
[9, 53, 33, 47, , 50, 17, "良"], [10, 80, 55, 80, , 75, 24, "良"], [11, 117, 81, 124, , 45, 24, "轻度污染"], [12, 99, 71, 142, , 62,
42, "良"],
[13, 95, 69, 130, , 74, 50, "良"], [14, 116, 87, 131, , 84, 40,
"轻度污染"]]
parallel =Parallel("平行坐标系-用户自定义指示器")
(c_schema=c_schema)
("parallel", data)
()
程序截图:
13. 极坐标系图
程序一:
from pyecharts import Polar
radius =['周一', '周二', '周三', '周四', '周五', '周六', '周日']
polar =Polar("极坐标系-堆叠柱状图示例", width=1200, height=600)
("A", [1, 2, 3, 4, 3, 5, 1], radius_data=radius, type='barRadius',
is_stack=True)
("B", [2, 4, 6, 1, 2, 3, 1], radius_data=radius, type='barRadius',
is_stack=True)
("C", [1, 2, 3, 4, 1, 2, 5], radius_data=radius, type='barRadius',
is_stack=True)
()
程序截图:
程序二:
from pyecharts import Polar
radius =['周一', '周二', '周三', '周四', '周五', '周六', '周日']
polar =Polar("极坐标系-堆叠柱状图示例", width=1200, height=600)
("", [1, 2, 3, 4, 3, 5, 1], radius_data=radius, type='barAngle',
is_stack=True)
("", [2, 4, 6, 1, 2, 3, 1], radius_data=radius, type='barAngle',
is_stack=True)
("", [1, 2, 3, 4, 1, 2, 5], radius_data=radius, type='barAngle',
is_stack=True)
()
程序截图:
14. 雷达图
程序一:
from pyecharts import Radar
schema =[ ("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000)]
v1 =[[4300, 10000, 28000, 35000, 50000, 19000]]
v2 =[[5000, 14000, 28000, 31000, 42000, 21000]]
radar =Radar()
(schema)
("预算分配", v1, is_splitline=True, is_axisline_show=True)
("实际开销", v2, label_color=["#4e79a7"], is_area_show=False)
()
程序截图:
程序二:
from pyecharts import Radar
value_bj =[ [55, 9, 56, , 18, 6, 1], [25, 11, 21, , 34, 9, 2], [56, 7,
63, , 14, 5, 3], [33, 7, 29, , 16, 6, 4]]
value_sh =[ [91, 45, 125, , 34, 23, 1], [65, 27, 78, , 45, 29, 2], [83,
60, 84, , 73, 27, 3], [109, 81, 121, , 68, 51, 4]]
c_schema=[{"name": "AQI", "max": 300, "min": 5}, {"name": "", "max": 250,
"min": 20}, {"name": "PM10", "max": 300, "min": 5},
{"name": "CO", "max": 5}, {"name": "NO2", "max": 200}, {"name":
"SO2", "max": 100}]
radar =Radar()
(c_schema=c_schema, shape='circle')
("北京", value_bj, item_color="#f9713c", symbol=None)
("上海", value_sh, item_color="#b3e4a1", symbol=None)
()
程序截图:
15. 散点图
from pyecharts import Scatter
v1 =[10, 20, 30, 40, 50, 60]
v2 =[10, 20, 30, 40, 50, 60]
scatter =Scatter("散点图示例")
("A", v1, v2)
("B", v1[::-1], v2)
()
程序截图:
16. 词云图
from pyecharts import WordCloud
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]
wordcloud =WordCloud(width=1300, height=620)
("", name, value, word_size_range=[20, 100])
()
程序截图:
17. 更多图
程序一:
import math
from pyecharts import Polar
data =[]
for i in range(101):
theta =i /100*360
r =5*(1+(theta /180*)
([r, theta])
hour =[i for i in range(1, 25)]
polar =Polar("极坐标系示例", width=800, height=500)
("Love", data, angle_data=hour, boundary_gap=False,start_angle=0)
()
运行截图:
程序二:
import math
from pyecharts import Polar
data =[]
for i in range(361):
t =i /180*
r =(2*t) *(2*t)
([r, i])
polar =Polar("极坐标系示例", width=1200, height=600)
("Color-Flower", data, start_angle=0, symbol=None, axis_range=[0, None],
area_color="#f71f24", area_opacity=
()
程序截图:
程序三:
import random
from pyecharts import Pie
attr =['A', 'B', 'C', 'D', 'E', 'F']
pie =Pie("饼图示例", width=1000, height=600)
("", attr, [(0, 100) for _ in range(6)], radius=[50, 55], center=[25,
50],is_random=True,is_label_show=True)
("", attr, [(20, 100) for _ in range(6)], radius=[0, 45], center=[25,
50],rosetype='area',is_label_show=True)
("", attr, [(0, 100) for _ in range(6)], radius=[50, 55], center=[65,
50],is_random=True,is_label_show=True)
("", attr, [(20, 100) for _ in range(6)], radius=[0, 45], center=[65,
50],rosetype='radius',is_label_show=True)
()
程序截图:
程序四:
from pyecharts import Bar
attr =["{}月".format(i) for i in range(1, 13)]
v1 =[, , , , , , , , , , , ]
v2 =[, , , , , , , , , , , ]
bar =Bar("柱状图示例")
("蒸发量", attr, v1, mark_line=["average"], mark_point=["max", "min"])
("降水量", attr, v2, mark_line=["average"], mark_point=["max", "min"])
()
程序截图:
程序五:
from pyecharts import Pie
pie =Pie('各类电影中"好片"所占的比例', "数据来着豆瓣",
title_pos='center')
("", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24],
label_pos='center', is_label_show=True, label_text_color=None, )
("", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24],
label_pos='center', is_label_show=True, label_text_color=None,
legend_pos='left')
("", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24],
label_pos='center', is_label_show=True, label_text_color=None)
("", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24],
label_pos='center', is_label_show=True, label_text_color=None)
("", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24],
label_pos='center', is_label_show=True, label_text_color=None)
("", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24],
label_pos='center', is_label_show=True, label_text_color=None)
("", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24],
label_pos='center', is_label_show=True, label_text_color=None)
("", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24],
label_pos='center', is_label_show=True, label_text_color=None)
("", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24],
label_pos='center', is_label_show=True, label_text_color=None)
("", ["犯罪", ""], [28, 72], center=[90, 70], radius=[18, 24],
label_pos='center', is_label_show=True, label_text_color=None,
is_legend_show=True, legend_top="center")
()
程序截图:
目前就介绍这些图吧,更多详细示例,请看pyecharts官网#/zh-cn/prepare,希望以上分享的内容能对你有所帮助。
版权声明:本文标题:pyecharts教程 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1704909199a466523.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论