pyecharts是一个用于生成echarts图表的类库。echarts是百度开源的一个数据可视化库,用echarts生成的图可视化效果非常棒。使用pyechart库可以在python中生成echarts数据图。
视觉效果还挺棒
柱形图绘制
from pyecharts import options as optsfrom pyecharts.charts import Bar, Pagefrom pyecharts.globals import ThemeTypedef bar_base_dict_config() -> Bar: c = ( Bar({'theme': ThemeType.MACARONS}) .add_xaxis(['伙食', '交通', '零食', '商品', '出游', '消费', '摄影']) .add_yaxis('同学A', [600, 20,30, 50, 100, 125, 200]) .add_yaxis('同学B', [650,25,25, 80, 150, 145, 100]) .set_global_opts( title_opts={'text': 'AB同学的生活开支', 'subtext': '通过 dict 进行配置'} ) ) return cbar_base_dict_config().render()
将产生一个html文件——render.html
折线图绘制
import pyecharts.options as optsfrom pyecharts.charts import Linedef line_base() -> Line: attr = ['10.13', '10.14', '10.15', '10.16' , '10.17' , '\ 10.18'] v1 = [1650, 1700, 1461, 1350, 1100, 1500] v2 = [1020, 575, 400, 350, 330, 480] c = ( Line() .add_xaxis(attr) .add_yaxis('成都_to_北京', v1) .add_yaxis('成都_to_昆明', v2) .set_global_opts(title_opts=opts.TitleOpts(title='航班价格折线图')) ) return cline_base().render()
效果图
饼图绘制
from pyecharts import options as optsfrom pyecharts.charts import Piefrom pyecharts.faker import Collector, Fakerdef pie_set_colors() -> Pie: c = ( Pie() .add('', [list(z) for z in zip(['上课','睡眠','餐饮','娱乐','聊天学习','健身'], [4,8,3,3,2,1])]) .set_colors(['blue', 'green', 'yellow', 'red', 'pink','orange']) .set_global_opts(title_opts=opts.TitleOpts(title='这一天天的')) .set_series_opts(label_opts=opts.LabelOpts(formatter='{b}: {c}')) ) return cpie_set_colors().render()
仅仅用于个人学习可视化记录操作
联系客服