Pyecharts入门教程
Pyecharts安装
!pip install pyecharts
导入
from pyecharts.charts import Bar
from pyecharts import options as opts
# 以下参数指定了使用Kesci提供的pyecharts_assets, 加载速度更快
bar = (
Bar(opts.InitOpts(js_host="https://cdn.kesci.com/lib/pyecharts_assets/"))
.add_xaxis(["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"])
.add_yaxis("商家A", [114, 55, 27, 101, 125, 27, 105])
.add_yaxis("商家B", [57, 134, 137, 129, 145, 60, 49])
.set_global_opts(
datazoom_opts=[opts.DataZoomOpts(is_show=True)],
title_opts=opts.TitleOpts(title="某商场销售情况")
)
)
bar.render_notebook()
from pyecharts import options as opts
from pyecharts.globals import ThemeType
# 导入主题:https://pyecharts.org/#/zh-cn/themes
# .LIGHT、.DARK、.CHALK、.ESSOS、.INFOGRAPHIC、.PURPLE_PASSION ...
from pyecharts.charts import Bar
# 导入柱状图
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
x = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
# 创建变量数据
bar = (
Bar(opts.InitOpts(width = '1000px',height = '500px',theme=ThemeType.INFOGRAPHIC))
.add_xaxis(x)
.add_yaxis("商家A", v1,is_selected = True)
.add_yaxis("商家B", v2,is_selected = True)
.set_global_opts(
# 设置全局参数
title_opts = opts.TitleOpts(title="商场数据显示"), # 设置title
xaxis_opts= opts.AxisOpts(
splitline_opts=opts.SplitLineOpts(is_show=True)
), # 设置x轴
yaxis_opts= opts.AxisOpts(
splitarea_opts=opts.SplitAreaOpts(is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1))
), # 设置y轴
toolbox_opts = opts.ToolboxOpts(is_show = True), # 设置工具箱
datazoom_opts= [opts.DataZoomOpts(range_start=10, range_end=80,is_zoom_lock=False)], # 设置slider
)
.set_series_opts(
# 设置系列配置
markpoint_opts=opts.MarkPointOpts(
data=[
opts.MarkPointItem(type_="max", name="最大值"),
opts.MarkPointItem(type_="min", name="最小值"),
]
),
markline_opts=opts.MarkLineOpts(
data=[
opts.MarkLineItem(type_="average", name="平均值"),
]
),
)
)
bar.render_notebook()
# 在线显示