安装
pip install pyecharts
1. 条形图 Bar
from pyecharts import Bar
movieName = ["战狼2","速度","功夫瑜伽","西游伏妖篇","变形金刚5","摔跤吧"]
movieMoney = [56.01, 26.94, 17.53, 16.49, 15.45, 12.96]
print(len(movieName), len(movieMoney))
bar = Bar(title="某年内地电影票房前20的电影", subtitle="这是一个子标题")
# 添加图表的数据, 或者配置信息
bar.add("电影信息",movieName, movieMoney)
# 默认情况下会生成一个render.html文件
bar.render()
结果:生成一个render.html
绘制多个条形图
from pyecharts import Bar
x_movies_name = ["猩球崛起", "敦刻尔克", "蜘蛛侠", "战狼2"]
y_16 = [15746, 312, 4497, 319]
y_15 = [12357, 156, 2045, 168]
y_14 = [2358, 399, 2358, 362]
bar = Bar(title="某年内地电影票房前20的电影", subtitle="子标题")
bar.add("2017-09-14", x_movies_name, y_14, mark_line=['min', 'max'], mark_point=['average'])
bar.add("2017-09-15", x_movies_name, y_15)
bar.add("2017-09-16", x_movies_name, y_16)
bar.render()
2. 散点图 Scatter
EffectScatter:动态散点图
Scatter:普通散点图
from pyecharts import EffectScatter, Scatter, Scatter3D
x_march = list(range(1, 32))
y_temp_march = [11, 17, 16, 11, 12, 11, 12, 6, 6, 7, 8, 9, 12, 15, 14, 17, 18, 21, 16, 17, 20, 14, 15, 15, 15, 19, 21,
22, 22, 22, 23]
# scatter= EffectScatter("北京3月份每天白天的最高气温随时间(天)变化的散点图")
scatter= Scatter("北京3月份白天变化的散点图", subtitle="xxxx")
# symbol_size散点图标记的大小;
scatter.add("3 月", x_march, y_temp_march, symbol_size=10, line_color='red')
scatter.add("4 月", x_march, y_temp_march, symbol_size=30