柱状图适用于二维数据,一个维度数据用来进行比较、数据展示等。可以直观的看到各组数据差异性,强调个体之间的比较。不适合数据项数较多的场景,容易混乱不清。
1、首先导入所需的包
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
2、简单的构建数据(虚拟数据):
top5 = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
.add_xaxis(["袜子","上衣","裤子","裙子","鞋子"])
.add_yaxis("", [55000,60000,65000,75000,75000],category_gap="50%",itemstyle_opts=opts.ItemStyleOpts(color='lightslategrey'),)
.set_global_opts(
title_opts=opts.TitleOpts(title="热销品牌TOP"),
datazoom_opts=opts.DataZoomOpts(),
)
.set_series_opts(
label_opts=opts.LabelOpts(is_show=True))
)
name.render_notebook()
结果如图:
3 、想要条形图的话可以加上.reversal_axis():
top5 = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
.add_xaxis(["袜子","上衣","裤子","裙子","鞋子"])
.add_yaxis("", [50000,50000,55000,65000,75000],category_gap="50%",itemstyle_opts=opts.ItemStyleOpts(color='lightslategrey'),)
.set_global_opts(
title_opts=opts.TitleOpts(title="热销商品TOP"),
datazoom_opts=opts.DataZoomOpts(),
)
.set_series_opts(
label_opts=opts.LabelOpts(is_show=True))
.reversal_axis()
)
store.render_notebook()
结果如图: