1. 绘制柱状图
from pyecharts.charts import Bar
from pyecharts import options as opts
index = ['商品948', '商品856', '商品621', '商品272', '商品563', '商品347', '商品597', '商品468', '商品986', '商品1000']
values = [29, 28, 27, 26, 24, 21, 19 ,18 ,16 ,13]
(Bar()
.add_xaxis(xaxis_data=index)
.add_yaxis(y_axis=values,
itemstyle_opts = opts.ItemStyleOpts(color='cornflowerblue'),
series_name='商品销量后十' )
.set_global_opts(title_opts = opts.TitleOpts(title='商品销量后十排名情况',subtitle='横轴表示商品ID'))
).render_notebook()
2. 绘制折线图
from pyecharts.charts import Line
from pyecharts import options as opts
(
Line()
.add_xaxis(xaxis_data=is_workday.index)
.add_yaxis(series_name='工作日',y_axis=is_workday,symbol="arrow",is_symbol_show=True)
.add_yaxis(series_name='非工作日',y_axis=not_workday)
.set_global_opts(title_opts=opts.TitleOpts(title='学生消费次数与工作日/非工作日的关系'))
).render_notebook()
3. 绘制柱形折线组合图
4. 绘制散点图
from pyecharts.charts import Scatter
from pyecharts import options as opts
scatter = Scatter()
scatter.add_xaxis(xaxis_data=labels)
scatter.add_yaxis(series_name='', y_axis=values, symbol_size=30)
scatter.render_notebook()
5. 绘制饼图
from pyecharts.charts import Pie
from pyecharts import options as opts
season_labels = ['春季','夏季','秋季','冬季']
season_values = [471348,918589,1061129,841613]
(
Pie()
.add(
'季节',
[list(z) for z in zip(season_labels,season_values)],
radius=['30%', '75%'],
center=['50%', '50%'],
rosetype='radius',
label_opts=opts.LabelOpts(is_show=False),
)
.set_global_opts(title_opts=opts.TitleOpts(title="不同季节中共享单车的使用情况"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c} {d}%"))
).render('时间维度分析_季节.html')
weather_labels = ['晴天 多云','雾天 阴天','小雪 小雨','大雨 大雪 大雾']
weather_values = [2338173,795952,158331,223]
(
Pie()
.add('',
[list(z) for z in zip(weather_labels, weather_values)],
radius=['30%', '75%'],
center=['50%', '50%'],
rosetype='radius',
label_opts=opts.LabelOpts(is_show=False),)
.set_global_opts(title_opts=opts.TitleOpts(title='不同天气中,共享单车使用情况'))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c} {d}%"))
).render('天气维度分析.html')
6.圆环图
from pyecharts.charts import Pie
from pyecharts import options as opts
edu_labels = ['本科', '大专', '硕士', '中技/中专', '高中', '博士']
edu_counts = [10503,5158,195,29,12,4]
(
Pie()
.add(
'学历',
data_pair=[list(z) for z in zip(edu_labels, edu_counts)],
radius=["45%", "70%"],
center=["50%", "50%"],
label_opts=opts.LabelOpts(is_show=True),
)
.set_global_opts(title_opts=opts.TitleOpts(title='学历占比圆环图',pos_left='40%'),
legend_opts=opts.LegendOpts(type_="scroll", pos_top="20%", pos_left="85%", orient="vertical"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c} {d}%"))
).render_notebook()
7. 绘制玫瑰饼图
from pyecharts.charts import Pie
from pyecharts import options as opts
people_labels = ['50-150人','150-500人','少于50人','1000-5000人','500-1000人','10000人以上','5000-10000人']
people_values = [4764, 3628, 3263, 1813, 1609, 505, 319]
(
Pie()
.add(
'人数',
[list(z) for z in zip(people_labels,people_values)],
radius=['30%', '75%'],
center=['50%', '50%'],
rosetype='radius',
label_opts=opts.LabelOpts(is_show=False),
)
.set_global_opts(title_opts=opts.TitleOpts(title='人数占比玫瑰图',pos_left='40%'),
legend_opts=opts.LegendOpts(type_="scroll", pos_top="20%", pos_left="85%", orient="vertical"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c} {d}%"))
).render_notebook()
8. 绘制嵌套子母饼图
inner_x_data = ['直达','营销广告','搜索引擎']
inner_y_data = [335, 679, 1548]
inner_data_pair = [list(z) for z in zip(inner_x_data, inner_y_data)]
outer_x_data = ['直达','营销广告','搜索引擎','邮件营销','联盟广告','视频广告','百度','谷歌','必应','其他']
outer_y_data = [335, 310, 234, 135, 1048, 251, 147, 102]
outer_data_pair = [list(z) for z in zip(outer_x_data, outer_y_data)]
pie_2 = Pie(init_opts=opts.InitOpts(width='800px', height='600px'))
pie_2.add(
series_name='访问来源',
data_pair= inner_data_pair,
radius=[0, "30%"],
label_opts=opts.LabelOpts(position='inner')
)
pie_2.add(
series_name='访问',
data_pair= outer_data_pair,
radius=['40%', "60%"],
label_opts=opts.LabelOpts(position='outside',
background_color='#eee',
border_color='#aaa',
border_width=1,
border_radius=40
)
)
pie_2.set_global_opts(
legend_opts=opts.LegendOpts(pos_left='left',
orient='vertical')
)
pie_2.render_notebook()
9. 绘制雷达图
from pyecharts import options as opts
from pyecharts.charts import Radar
exp = [[468,322,265,164,31,21,4]]
(
Radar()
.add_schema(
schema=[
opts.RadarIndicatorItem(name='3-4年经验',max_=500),
opts.RadarIndicatorItem(name='2年经验', max_=400),
opts.RadarIndicatorItem(name='1年经验', max_=300),
opts.RadarIndicatorItem(name='5-7年经验', max_=200),
opts.RadarIndicatorItem(name='无需经验', max_=100),
opts.RadarIndicatorItem(name='8-9年经验', max_=50),
opts.RadarIndicatorItem(name='10年以上经验', max_=50),
]
)
.add(
'广州',exp,
color='red',
areastyle_opts=opts.AreaStyleOpts(
opacity=0.5,
color='red'
),
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(title_opts=opts.TitleOpts(title='广州地区经验要求雷达图'))
).render_notebook()
10. 绘制词云图
11. 绘制中国地图
(
Map()
.add(series_name='', data_pair=[(i,int(j)) for i,j in zip(local_labels, local_values)],
)
.set_global_opts(
title_opts=opts.TitleOpts(title='职位地理位置分布图'),
visualmap_opts=opts.VisualMapOpts(max_=2000, is_piecewise=False),
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=True),showLegendSymbol=False)
).render_notebook()
11. 绘制世界地图
from pyecharts import options as opts
from pyecharts.charts import Pie
label=['Mac口红','Tom Ford口红','圣罗兰','纪梵希','花西子','迪奥','阿玛尼','香奈儿']
values = [300,300,300,300,44,300,300,300]
def pie_base():
c = (
Pie()
.add("",[list(z) for z in zip(label,values)])
.set_global_opts(title_opts = opts.TitleOpts(title="口红品牌分析"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c} {d}%"))
)
return c
pie_base().render()
12.漏斗图
exp = [6054,3911,2862,2161, 633,193,84,3]
phase = ['3-4年经验 ', '2年经验 ', '1年经验 ', '5-7年经验 ', '无需经验 ', '8-9年经验 ','10年以上经验 ', '在校生/应届生 ']
(
Funnel()
.add("阶段", [list(z) for z in zip(phase, exp)])
.set_global_opts(title_opts=opts.TitleOpts(title="经验漏斗图", pos_left='45%'),
legend_opts=opts.LegendOpts(type_="scroll", pos_top="30%", pos_left="80%", orient="vertical"))
).render_notebook()