pyecharts是基于ECharts图表库开发的python第三方模块。
ECharts是一个纯Javascript的商业级图表库,兼容当前绝大部分浏览器,能够创建类型丰富,精美生动,可交互,可高度个性化定制的数据可视化效果。
安装:pip3 install pyecharts
from pyecharts import options as opts from pyecharts.charts import Bar from pyecharts.globals import ThemeType x = ['连衣裙', '短裤', '运动套装', '牛仔裤', '针织衫', '半身裙', '衬衫', '阔腿裤', '打底裤'] y1 = [36, 56, 60, 78, 90, 20, 50, 70, 10] y2 = [16, 30, 50, 90, 45, 10, 60, 54, 40] chart = Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK)) chart.add_xaxis(x) chart.add_yaxis('分店A', y1) chart.add_yaxis('分店B', y2) chart.set_global_opts(title_opts=opts.TitleOpts(title='产品销售额对比图', pos_left='left'), yaxis_opts=opts.AxisOpts(name='销售业绩(元)', name_location='end'), xaxis_opts=opts.AxisOpts(name='产品', name_location='end'), tooltip_opts=opts.TooltipOpts(is_show=True, formatter='{a}2.2 绘制漏斗图
{b}:{c}', background_color='black', border_width=15), legend_opts=opts.LegendOpts(is_show=False), toolbox_opts=opts.ToolboxOpts(is_show=True, orient='horizontal'), visualmap_opts=opts.VisualMapOpts(is_show=True, type_='color', min_=0, max_=100, orient='vertical'), datazoom_opts=opts.DataZoomOpts(is_show=True, type_='slider')) chart.render('图表配置项.html')
import pyecharts.options as opts from pyecharts.charts import Funnel x = ['浏览商品', '放入购物车', '生成订单', '支付订单', '完成交易'] y = [1000, 900, 400, 360, 320] data = [i for i in zip(x, y)] chart = Funnel() chart.add(series_name='人数', data_pair=data, label_opts=opts.LabelOpts(is_show=True, position='inside'), tooltip_opts=opts.TooltipOpts(trigger='item', formatter='{a}:{c}')) chart.set_global_opts(title_opts=opts.TitleOpts(title='电商网站流量转化漏斗图', pos_left='center'), legend_opts=opts.LegendOpts(is_show=False)) chart.render('漏斗图.html') import pyecharts.options as opts from pyecharts.charts import Funnel x = ['浏览商品', '放入购物车', '生成订单', '支付订单', '完成交易'] y = [1000, 900, 400, 360, 320] data = [i for i in zip(x, y)] chart = Funnel() chart.add(series_name='人数', data_pair=data, sort_='ascending', gap=15, label_opts=opts.LabelOpts(is_show=True, position='inside'), tooltip_opts=opts.TooltipOpts(trigger='item', formatter='{a}:{c}')) chart.set_global_opts(title_opts=opts.TitleOpts(title='电商网站流量转化漏斗图', pos_left='center'), legend_opts=opts.LegendOpts(is_show=False)) chart.render('漏斗图.html')2.3 绘制涟漪特效散点图
import pandas as pd import pyecharts.options as opts from pyecharts.charts import EffectScatter data = pd.read_excel('客户购买力统计表.xlsx') x = data['年龄'].tolist() y = data['消费金额(元)'].tolist() chart = EffectScatter() chart.add_xaxis(x) chart.add_yaxis(series_name='年龄,消费金额(元)', y_axis=y, label_opts=opts.LabelOpts(is_show=False), symbol_size=15) chart.set_global_opts(title_opts=opts.TitleOpts(title='客户购买力散点图'), yaxis_opts=opts.AxisOpts(type_='value', name='消费金额(元)', name_location='middle', name_gap=40), xaxis_opts=opts.AxisOpts(type_='value', name='年龄', name_location='middle', name_gap=40), tooltip_opts=opts.TooltipOpts(trigger='item', formatter='{a}:{c}')) chart.render('涟漪特效散点图.html')2.4 绘制水球图
import pyecharts.options as opts from pyecharts.charts import Liquid a = 68 t = 100 chart = Liquid() chart.add(series_name = '商品A', data = [a / t]) chart.set_global_opts(title_opts = opts.TitleOpts(title = '产品销售业绩达成率', pos_left = 'center')) chart.render('水球图.html') import pyecharts.options as opts from pyecharts.charts import Liquid a = 68 t = 100 chart = Liquid() chart.add(series_name = '商品A', data = [a / t], shape = 'rect') chart.set_global_opts(title_opts = opts.TitleOpts(title = '产品销售业绩达成率', pos_left = 'center')) chart.render('水球图.html') import pyecharts.options as opts from pyecharts.charts import Liquid a1 = 68 a2 = 120 a3 = 37 t = 100 chart = Liquid() chart.set_global_opts(title_opts=opts.TitleOpts(title='产品销售业绩达成率', pos_left='center')) chart.add(series_name='商品A', data=[a1 / t], center=['20%', '50%']) chart.add(series_name='商品B', data=[a2 / t], center=['50%', '50%']) chart.add(series_name='商品C', data=[a3 / t], center=['80%', '50%']) chart.render('水球图.html')2.5 绘制仪表盘
import pyecharts.options as opts from pyecharts.charts import Gauge chart = Gauge() chart.add(series_name = '业务指标', data_pair = [('完成率', '62.25')], split_number = 10, radius = '80%', title_label_opts = opts.LabelOpts(font_size = 30, color = 'red', font_family = 'Microsoft YaHei')) chart.set_global_opts(legend_opts = opts.LegendOpts(is_show = False), tooltip_opts = opts.TooltipOpts(is_show = True, formatter = '{a}2.6 绘制词云图
{b}:{c}%')) chart.render('仪表盘.html')
import pandas as pd import pyecharts.options as opts from pyecharts.charts import WordCloud data = pd.read_excel('电影票房统计.xlsx') name = data['电影名称'] value = data['总票房(亿元)'] data1 = [z for z in zip(name, value)] chart = WordCloud() chart.add('总票房(亿元)', data_pair = data1, word_size_range = [6, 66]) chart.set_global_opts(title_opts=opts.TitleOpts(title = '电影票房分析', title_textstyle_opts = opts.TextStyleOpts(font_size = 30)), tooltip_opts = opts.TooltipOpts(is_show = True)) chart.render('词云图.html') import pandas as pd import pyecharts.options as opts from pyecharts.charts import WordCloud data = pd.read_excel('电影票房统计.xlsx') name = data['电影名称'] value = data['总票房(亿元)'] data1 = [z for z in zip(name, value)] chart = WordCloud() chart.add('总票房(亿元)', data_pair = data1, shape = 'star', word_size_range = [6, 66]) chart.set_global_opts(title_opts=opts.TitleOpts(title = '电影票房分析', title_textstyle_opts = opts.TextStyleOpts(font_size = 30)), tooltip_opts = opts.TooltipOpts(is_show = True)) chart.render('词云图.html')2.7 绘制K线图
import tushare as ts data = ts.get_k_data('000005', start = '2010-01-01', end = '2020-01-01') print(data.head()) data.to_excel('股价数据.xlsx', index = False) import pandas as pd from pyecharts import options as opts from pyecharts.charts import Kline data = pd.read_excel('股价数据.xlsx') x = list(data['date']) open = data['open'] close = data['close'] lowest = data['low'] highest = data['high'] y = [list(z) for z in zip(open, close, lowest, highest)] chart = Kline() chart.add_xaxis(x) chart.add_yaxis('股价', y) chart.set_global_opts(xaxis_opts = opts.AxisOpts(is_scale = True), yaxis_opts = opts.AxisOpts(is_scale = True, splitarea_opts = opts.SplitAreaOpts(is_show = True, areastyle_opts = opts.AreaStyleOpts(opacity = 1))), datazoom_opts = [opts.DataZoomOpts(type_ = 'inside')], title_opts = opts.TitleOpts(title = '股价走势图')) chart.render('K线图.html')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)