pythonpyecharts实现⼀个⽂件绘制多张图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%") # 添加要展⽰的图表,并设置显⽰位置
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)
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.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中添加图表
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)python怎么读取py文件
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 ⽉')
以上这篇python pyecharts 实现⼀个⽂件绘制多张图就是⼩编分享给⼤家的全部内容了,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论