python pyecharts 实现一个文件绘制多张图


Posted in Python onMay 13, 2020

Grid并行显示多张图

注意: 第一个图需为 有 x/y 轴的图,即不能为 Pie,其他位置顺序任意

from pyecharts import Bar, Line, Scatter, EffectScatter, Grid
'''
 Grid类:并行显示多个图表 TODO 第一个图需为 有 x/y 轴的图,即不能为 Pie,其他位置顺序任意。
'''

attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar("柱状图示例", title_pos="65%")
bar.add("商家A", attr, v1, is_stack=True)
bar.add("商家B", attr, v2, is_stack=True, legend_pos="80%")

line = Line("折线图示例")
attr = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
line.add(
 "最高气温",
 attr,
 [11, 11, 15, 13, 12, 13, 10],
 mark_point=["max", "min"],
 mark_line=["average"],
)
line.add(
 "最低气温",
 attr,
 [1, -2, 2, 5, 3, 2, 0],
 mark_point=["max", "min"],
 mark_line=["average"],
 legend_pos="20%",
)

v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
scatter = Scatter("散点图示例", title_top="50%", title_pos="65%")
scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%")

es = EffectScatter("动态散点图示例", title_top="50%")
es.add(
 "es",
 [11, 11, 15, 13, 12, 13, 10],
 [1, -2, 2, 5, 3, 2, 0],
 effect_scale=6,
 legend_top="50%",
 legend_pos="20%",
)

# TODO 配置Grid类
grid = Grid(height=720, width=1200) # 初始化,参数可传page_title,width,height
grid.add(bar, grid_bottom="60%", grid_left="60%") # 添加要展示的图表,并设置显示位置
grid.add(line, grid_bottom="60%", grid_right="60%") # 添加要展示的图表,并设置显示位置
grid.add(scatter, grid_top="60%", grid_left="60%") # 添加要展示的图表,并设置显示位置
grid.add(es, grid_top="60%", grid_right="60%") # 添加要展示的图表,并设置显示位置

grid.render("./pyecharts_html/Grid_并行显示多张图表.html")

overlap图表混合使用

from pyecharts import Line, Bar, Overlap
'''
 多个x y轴示例
'''

attr = ["{}月".format(i) for i in range(1, 13)]
v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]

bar = Bar()
bar.add("蒸发量", attr, v1)
bar.add("降水量", attr, v2, yaxis_formatter=" ml",
 yaxis_interval=50, yaxis_max=250)

line = Line()
line.add("平均温度", attr, v3, yaxis_formatter=" °C", yaxis_interval=5)

overlap = Overlap(width=1200, height=600) # 实例化
# 默认不新增 x y 轴,并且 x y 轴的索引都为 0
overlap.add(bar)
# 新增一个 y 轴,此时 y 轴的数量为 2,第二个 y 轴的索引为 1(索引从 0 开始),所以设置 yaxis_index = 1
# 由于使用的是同一个 x 轴,所以 x 轴部分不用做出改变
overlap.add(line, yaxis_index=1, is_add_yaxis=True)

overlap.render("./pyecharts_html/Overlap_图表混合.html")

Page一个页面顺序渲染多个图表

from pyecharts import *

page = Page() # 实例化page类

# line
attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
line = Line("折线图示例")
line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10],
  mark_point=["max", "min"], mark_line=["average"])
line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0],
  mark_point=["max", "min"], mark_line=["average"])

page.add(line) # TODO 向page中添加图表

# pie
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [11, 12, 13, 10, 10, 10]
pie = Pie("饼图-圆环图示例", title_pos='center')
pie.add("", attr, v1, radius=[40, 75], label_text_color=None,
 is_label_show=True, legend_orient='vertical', legend_pos='left')

page.add(pie) # TODO 向page中添加图表

# kline
v1 = [[2320.26, 2320.26, 2287.3, 2362.94],
 [2300, 2291.3, 2288.26, 2308.38],
 [2295.35, 2346.5, 2295.35, 2345.92],
 [2347.22, 2358.98, 2337.35, 2363.8],
 [2360.75, 2382.48, 2347.89, 2383.76],
 [2383.43, 2385.42, 2371.23, 2391.82],
 [2377.41, 2419.02, 2369.57, 2421.15],
 [2425.92, 2428.15, 2417.58, 2440.38],
 [2411, 2433.13, 2403.3, 2437.42],
 [2432.68, 2334.48, 2427.7, 2441.73],
 [2430.69, 2418.53, 2394.22, 2433.89],
 [2416.62, 2432.4, 2414.4, 2443.03],
 [2441.91, 2421.56, 2418.43, 2444.8],
 [2420.26, 2382.91, 2373.53, 2427.07],
 [2383.49, 2397.18, 2370.61, 2397.94],
 [2378.82, 2325.95, 2309.17, 2378.82],
 [2322.94, 2314.16, 2308.76, 2330.88],
 [2320.62, 2325.82, 2315.01, 2338.78],
 [2313.74, 2293.34, 2289.89, 2340.71],
 [2297.77, 2313.22, 2292.03, 2324.63],
 [2322.32, 2365.59, 2308.92, 2366.16],
 [2364.54, 2359.51, 2330.86, 2369.65],
 [2332.08, 2273.4, 2259.25, 2333.54],
 [2274.81, 2326.31, 2270.1, 2328.14],
 [2333.61, 2347.18, 2321.6, 2351.44],
 [2340.44, 2324.29, 2304.27, 2352.02],
 [2326.42, 2318.61, 2314.59, 2333.67],
 [2314.68, 2310.59, 2296.58, 2320.96],
 [2309.16, 2286.6, 2264.83, 2333.29],
 [2282.17, 2263.97, 2253.25, 2286.33],
 [2255.77, 2270.28, 2253.31, 2276.22]]
kline = Kline("K 线图示例")
kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1)

page.add(kline) # TODO 向page中添加图表

# radar
schema = [
 ("销售", 6500), ("管理", 16000), ("信息技术", 30000),
 ("客服", 38000), ("研发", 52000), ("市场", 25000)
]
v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
v2 = [[5000, 14000, 28000, 31000, 42000, 21000]]
radar = Radar("雷达图示例")
radar.config(schema)
radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True)
radar.add("实际开销", v2, label_color=["#4e79a7"], is_area_show=False,
  legend_selectedmode='single')

page.add(radar) # TODO 向page中添加图表
page.render("./pyecharts_html/Page_一个页面渲染多张图表.html")

Timeline:时间线轮播多图

from pyecharts import Bar, Line, Timeline, Overlap
from random import randint

attr = ["{}月".format(i) for i in range(1, 7)]
bar = Bar("1 月份数据", "数据纯属虚构")
bar.add("bar", attr, [randint(10, 50) for _ in range(6)])
line = Line()
line.add("line", attr, [randint(50, 80) for _ in range(6)])
overlap = Overlap()
overlap.add(bar)
overlap.add(line)

bar_1 = Bar("2 月份数据", "数据纯属虚构")
bar_1.add("bar", attr, [randint(10, 50) for _ in range(6)])
line_1 = Line()
line_1.add("line", attr, [randint(50, 80) for _ in range(6)])
overlap_1 = Overlap()
overlap_1.add(bar_1)
overlap_1.add(line_1)

bar_2 = Bar("3 月份数据", "数据纯属虚构")
bar_2.add("bar", attr, [randint(10, 50) for _ in range(6)])
line_2 = Line()
line_2.add("line", attr, [randint(50, 80) for _ in range(6)])
overlap_2 = Overlap()
overlap_2.add(bar_2)
overlap_2.add(line_2)

bar_3 = Bar("4 月份数据", "数据纯属虚构")
bar_3.add("bar", attr, [randint(10, 50) for _ in range(6)])
line_3 = Line()
line_3.add("line", attr, [randint(50, 80) for _ in range(6)])
overlap_3 = Overlap()
overlap_3.add(bar_3)
overlap_3.add(line_3)

bar_4 = Bar("5 月份数据", "数据纯属虚构")
bar_4.add("bar", attr, [randint(10, 50) for _ in range(6)])
line_4 = Line()
line_4.add("line", attr, [randint(50, 80) for _ in range(6)])
overlap_4 = Overlap()
overlap_4.add(bar_4)
overlap_4.add(line_4)

timeline = Timeline(
   page_title = "页标签名",
   width=600,
   height=600,
   is_auto_play= True, # 是否自动播放,默认=False
   is_loop_play= True, # 是否循环播放
   is_rewind_play=False, # 反向播放
   is_timeline_show=True, # 是否显示时间线,默认=true
   timeline_play_interval=1000, # 播放间隔,ms
   timeline_symbol= "arrow", # 时间点标记图形, 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow'
   timeline_symbol_size= [15,8], # 图形大小,可以是数字和列表,列表表示宽高
   timeline_left= "1% ", # 距离左边距离 , timeline_right
   timeline_bottom=0, # timeline_top
  )
timeline.add(overlap, '1 月')
timeline.add(overlap_1, '2 月')
timeline.add(overlap_2, '3 月')
timeline.add(overlap_3, '4 月')
timeline.add(overlap_4, '5 月')
timeline.render("./pyecharts_html/Timeline_时间线轮播多张图表.html")

以上这篇python pyecharts 实现一个文件绘制多张图就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
videocapture库制作python视频高速传输程序
Dec 23 Python
Python编程判断一个正整数是否为素数的方法
Apr 14 Python
Python设计模式之代理模式简单示例
Jan 09 Python
python实现mysql的读写分离及负载均衡
Feb 04 Python
可能是最全面的 Python 字符串拼接总结【收藏】
Jul 09 Python
Python定时任务sched模块用法示例
Jul 16 Python
Python 网络编程之UDP发送接收数据功能示例【基于socket套接字】
Oct 11 Python
python实现计算器功能
Oct 31 Python
python机器学习实现决策树
Nov 11 Python
解决Keras 中加入lambda层无法正常载入模型问题
Jun 16 Python
Keras中的两种模型:Sequential和Model用法
Jun 27 Python
PyQt5 QThread倒计时功能的实现代码
Apr 02 Python
Django与pyecharts结合的实例代码
May 13 #Python
django Layui界面点击弹出对话框并请求逻辑生成分页的动态表格实例
May 12 #Python
Python爬取阿拉丁统计信息过程图解
May 12 #Python
PyPDF2读取PDF文件内容保存到本地TXT实例
May 12 #Python
Python3.7下安装pyqt5的方法步骤(图文)
May 12 #Python
小 200 行 Python 代码制作一个换脸程序
May 12 #Python
python3用PyPDF2解析pdf文件,用正则匹配数据方式
May 12 #Python
You might like
shopex中集成的站长统计功能的代码简单分析
2011/08/11 PHP
PHP文件缓存内容保存格式实例分析
2014/08/20 PHP
10个php函数实用却不常见
2015/10/13 PHP
深入理解PHP变量的值类型和引用类型
2015/10/21 PHP
php mysql like 实现多关键词搜索的方法
2016/10/29 PHP
javascript Demo模态窗口
2009/12/06 Javascript
jQeury淡入淡出需要注意的问题
2010/09/08 Javascript
JS关键字变色实现思路及代码
2013/02/21 Javascript
关于Javascript与iframe的那些事儿
2013/07/04 Javascript
jQuery中closest()函数用法实例
2015/01/07 Javascript
JavaScript中的时间处理小结
2016/02/24 Javascript
jQuery中each()、find()和filter()等节点操作方法详解(推荐)
2016/05/25 Javascript
javascript中异常处理案例(推荐)
2016/10/03 Javascript
完美解决UI-Grid表格元素中多个空格显示为一个空格的问题
2017/04/25 Javascript
xmlplus组件设计系列之分隔框(DividedBox)(8)
2017/05/02 Javascript
微信小程序实现跑马灯效果完整代码(附效果图)
2018/05/30 Javascript
vue项目中添加单元测试的方法
2018/07/21 Javascript
在vue 中使用 less的教程详解
2018/09/26 Javascript
从零开始搭建vue移动端项目到上线的步骤
2018/10/15 Javascript
vue实现节点增删改功能
2019/09/26 Javascript
Python基于列表模拟堆栈和队列功能示例
2018/01/05 Python
如何用C代码给Python写扩展库(Cython)
2019/05/17 Python
Tensorflow Summary用法学习笔记
2020/01/10 Python
详解Python IO编程
2020/07/24 Python
HTML5图片层叠的实现示例
2020/07/07 HTML / CSS
Pedro官网:新加坡时尚品牌
2019/08/27 全球购物
阿联酋彩妆品牌:OUD MILANO
2019/10/06 全球购物
毕业生机械建模求职信
2013/10/14 职场文书
家居饰品店创业计划书
2014/01/31 职场文书
教师自我反思材料
2014/02/14 职场文书
2014年党员公开承诺践诺书
2014/03/25 职场文书
2014年最新个人对照检查材料范文
2014/09/25 职场文书
幼儿园教师岗位职责
2015/04/02 职场文书
2015年团支书工作总结
2015/04/03 职场文书
闪闪的红星观后感
2015/06/08 职场文书
Java实现经典游戏泡泡堂的示例代码
2022/04/04 Java/Android