常用图形:柱形图-折线图-饼图-散点图
from pyecharts import Line, Bar, Pie, EffectScatter
# 数据
attr =["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 =[5, 20, 36, 10, 10, 100]
v2 =[55, 60, 16, 20, 15, 80]
柱形图
bar = Bar('柱形图', '库存量')
bar.add('服装', attr, v1, is_label_show=True)
bar.show_config()
bar.render(path='./data/01-01柱形图.html')
bar2 = Bar("显示标记线和标记点")
bar2.add('商家A', attr, v1, mark_point=['avgrage'])
bar2.add('商家B', attr, v2, mark_point=['min', 'max'])
bar2.show_config()
bar2.render(path='./data/01-02标记点柱形图.html')
bar3 = Bar("水平显示")
bar3.add('商家A', attr, v1)
bar3.add('商家B', attr, v2, is_convert=True)
bar3.show_config()
bar3.render(path='./data/01-03水平柱形图.html')
对应的图像如下
01-01柱形图.png
01-02标记点柱形图.png
01-03水平柱形图.png
折线图
# 普通折线图
line = Line('折线图')
line.add('商家A', attr, v1, mark_point=['max'])
line.add('商家B', attr, v2, mark_point=['min'], is_smooth=True)
line.show_config()
line.render(path='./data/01-04折线图.html')
# 阶梯折线图
line2 = Line('阶梯折线图')
line2.add('商家A', attr, v1, is_step=True, is_label_show=True)
line2.show_config()
line2.render(path='./data/01-05阶梯折线图.html')
# 面积折线图
line3 =Line("面积折线图")
line3.add("商家A", attr, v1, is_fill=True, line_opacity=0.2, area_opacity=0.4, symbol=None, mark_point=['max'])
line3.add("商家B", attr, v2, is_fill=True, area_color='#a3aed5', area_opacity=0.3, is_smooth=True)
line3.show_config()
line3.render(path='./data/01-06面积折线图.html')
对应图形如下
01-04折线图.png
01-05阶梯折线图.png
01-06面积折线图.png
柱形图-折线图
# 柱形图-折线图
from pyecharts import Bar, Line, Overlap
att = ['A', 'B', 'C', 'D', 'E', 'F']
v3 = [10, 20, 30, 40, 50, 60]
v4 = [38, 28, 58, 48, 78, 68]
bar = Bar("柱形图-折线图")
bar.add('bar', att, v3)
line = Line()
line.add('line', att, v4)
overlap = Overlap()
overlap.add(bar)
overlap.add(line)
overlap.show_config()
overlap.render(path='./data/01-066柱形图-折线图.html')
01-066柱形图-折线图.png
饼图
# 饼图
pie = Pie('饼图')
pie.add('芝麻饼', attr, v1, is_label_show=True)
pie.show_config()
pie.render(path='./data/01-07饼图.html')
# 玫瑰饼图
pie2 = Pie("饼图-玫瑰图示例", title_pos='center', width=900)
pie2.add("商品A", attr, v1, center=[25, 50], is_random=True, radius=[30, 75], rosetype='radius')
pie2.add("商品B", attr, v2, center=[75, 50], is_random=True, radius=[30, 75], rosetype='area', is_legend_show=False, is_label_show=True)
pie2.show_config()
pie2.render(path='./data/01-08玫瑰饼图.html')
01-07饼图.png
01-08玫瑰饼图.png
散点图
静态散点图
from pyecharts import Scatter
# 散点图
v1 =[10, 20, 30, 40, 50, 60]
v2 =[10, 20, 30, 40, 50, 60]
scatter =Scatter("散点图示例")
scatter.add("A", v1, v2)
scatter.add("B", v1[::-1], v2)
scatter.show_config()
scatter.render(path='./data/03-06散点图.html')
# 散点打印Pyecharts字体 白底图片
scatter =Scatter("散点图示例")
v1, v2 = scatter.draw("./data/two.jpg")
scatter.add("pyecharts", v1, v2, is_random=True)
scatter.show_config()
scatter.render(path='./data/03-06打印字体.html')
03-06散点图.png
动态散点图
from pyecharts import EffectScatter
attr =["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 =[5, 20, 36, 10, 10, 100]
v2 =[55, 60, 16, 20, 15, 80]
# 动态散点图
es =EffectScatter("动态散点图")
# v1 x坐标 v2 y坐标
es.add("商家", v1, v2)
es.show_config()
es.render('./data/01-09散点图.html')
# 动态散点图各种图形
es = 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.show_config()
es.render(path = "./data/01-10动态散点图各种图形.html")
图片为动图,效果很炫
01-09散点图.png
01-10动态散点图各种图形.png
综合图
多个饼图
from pyecharts import Pie
pie =Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center')
pie.add("", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None, )
pie.add("", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None, legend_pos='left')
pie.add("", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None)
pie.add("", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None)
pie.add("", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None)
pie.add("", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None)
pie.add("", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None)
pie.add("", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None)
pie.add("", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None)
pie.add("", ["犯罪", ""], [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")
pie.show_config()
pie.render(path='./data/01-多个饼图.html')
多个饼图.png
多标记柱形图
from pyecharts import Bar
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]
bar =Bar("柱状图示例")
bar.add("蒸发量", attr, v1, mark_line=["average"], mark_point=["max", "min"])
bar.add("降水量", attr, v2, mark_line=["average"], mark_point=["max", "min"])
bar.show_config()
bar.render(path='./data/02-多标记柱形图.html')
02-多标记柱形图.png
支持保存做种格式
对象.render(path='snapshot.html')
对象.render(path='snapshot.png')
对象.render(path='snapshot.pdf')
举个栗子:
bar = Bar("我的第一个图表", "这里是副标题")
bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90])
# bar.print_echarts_options()
bar.render(path='snapshot.html')
bar.render(path='snapshot.png')
bar.render(path='snapshot.pdf')
pyecharts绘画优美图形<一>:最全地图
pyecharts绘画优美图形<二>:柱形图-折线图-饼图
pyecharts绘画优美图形<三>:仪表盘 - 漏斗图 - 关系图 - 水球 - 极坐标 - 雷达
pyecharts绘画优美图形<四>:词云--支持中文
关注公众号:Python疯子 后台回复: pyecharts 获取源代码
分享最实用的Python功能,欢迎您的关注
Python疯子.jpg
网友评论