1 基本柱状图
from pyecharts import options as opts
from pyecharts.charts import Bar
l1 = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
l2 = [100, 200, 300, 400, 500, 600, 700]
l3 = [111, 222, 333, 444, 333, 222, 111]
bar = (
Bar()
.add_xaxis(l1)
.add_yaxis("基本柱状图", l3)
.set_global_opts(title_opts=opts.TitleOpts(title="基本柱状图", subtitle="副标题"))
)
bar.render_notebook()
2 带坐标轴标签的基本柱状图
from pyecharts import options as opts
from pyecharts.charts import Bar
l1=['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
l2=[100,200,300,400,500,600,700]
bar = (
Bar()
.add_xaxis(l1)
.add_yaxis("基本柱状图-轴标签", l2)
.set_global_opts(
title_opts=opts.TitleOpts(title="基本柱状图-轴标签"),
yaxis_opts=opts.AxisOpts(name="人流量"),
xaxis_opts=opts.AxisOpts(name="星期"),
)
)
bar.render_notebook()
- 显示
3 双纵坐标的柱状图
from pyecharts import options as opts
from pyecharts.charts import Bar
l1=['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
l2=[100,200,300,400,500,400,300]
l3=[300,400,500,400,300,200,100]
bar = (
Bar()
.add_xaxis(l1)
.add_yaxis("纵坐标1", l2)
.add_yaxis("纵坐标2", l3)
.set_global_opts(title_opts=opts.TitleOpts(title="双纵坐标柱状图", subtitle="我是副标题"),
toolbox_opts=opts.BrushOpts(),)
)
bar.render_notebook()
- 显示
4 设置轴距、轴颜色的柱状图
from pyecharts import options as opts
from pyecharts.charts import Bar
l1=['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
l2=[100,200,300,400,500,400,300]
bar = (
Bar()
.add_xaxis(l1)
.add_yaxis("l2",l2,category_gap=50, color='#000000')
.set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副标题"))
)
bar.render_notebook()
- 显示
5 横向柱状图
from pyecharts import options as opts
from pyecharts.charts import Bar
l1=['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
l2=[100,200,300,400,500,400,300]
l3=[300,400,500,400,300,200,100]
bar = (
Bar()
.add_xaxis(l1)
.add_yaxis("l2", l2)
.add_yaxis("l3", l3)
.reversal_axis()
.set_series_opts(label_opts=opts.LabelOpts(position="right"))
.set_global_opts(title_opts=opts.TitleOpts(title="横向柱状图"))
)
bar.render_notebook()
- 显示
6.1 标记线柱状图
from pyecharts import options as opts
from pyecharts.charts import Bar
import random
l1=['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
l2=[100,200,300,400,500,400,300]
bar = (
Bar()
.add_xaxis(l1)
.add_yaxis("l2", l2)
.set_global_opts(title_opts=opts.TitleOpts(title="标记线柱状图"))
.set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
markline_opts=opts.MarkLineOpts(
data=[
opts.MarkLineItem(type_="min", name="最小值"),
opts.MarkLineItem(type_="max", name="最大值"),
opts.MarkLineItem(type_="average", name="平均值"),
]
),
)
)
bar.render_notebook()
- 显示
6.2 标记点柱状图
from pyecharts import options as opts
from pyecharts.charts import Bar
import random
l1=['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
l2=[100,200,300,400,500,400,300]
bar = (
Bar()
.add_xaxis(l1)
.add_yaxis("标记点柱状图", l2)
.set_global_opts(title_opts=opts.TitleOpts(title="标记点柱状图"))
.set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
markpoint_opts=opts.MarkPointOpts(
data=[
opts.MarkPointItem(type_="min", name="最小值"),
opts.MarkPointItem(type_="max", name="最大值"),
opts.MarkPointItem(type_="average", name="平均值"),
]
),
)
)
bar.render_notebook()
- 显示
7 旋转轴标签
from pyecharts import options as opts
from pyecharts.charts import Bar
import random
l1=['很长的坐标轴{}'.format(i) for i in range(10)]
l2=[random.choice(range(10,100,10)) for i in range(10)]
bar = (
Bar()
.add_xaxis(l1)
.add_yaxis("l2", l2)
.set_global_opts(xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)),
title_opts=opts.TitleOpts(title="Bar-旋转X轴标签", subtitle="解决标签名字过长的问题"))
)
bar.render_notebook()
- 显示
8.1 区域缩放柱状图 - 鼠标滚轮缩放(inside)
from pyecharts import options as opts
from pyecharts.charts import Bar
import random
l1=['{}日'.format(i) for i in range(1,31)]
l2=[random.choice(range(100,3100,100)) for i in range(1,31)]
bar = (
Bar()
.add_xaxis(l1)
.add_yaxis("l2", l2)
.set_global_opts(title_opts=opts.TitleOpts(title="区域缩放柱状图"),
datazoom_opts=opts.DataZoomOpts(type_="inside"))
)
bar.render_notebook()
- 显示
8.2 区域缩放柱状图 - 滑块拖动缩放(slider)
from pyecharts import options as opts
from pyecharts.charts import Bar
import random
l1=['{}日'.format(i) for i in range(1,31)]
l2=[random.choice(range(100,3100,100)) for i in range(1,31)]
bar = (
Bar()
.add_xaxis(l1)
.add_yaxis("l2", l2)
.set_global_opts(title_opts=opts.TitleOpts(title="区域缩放柱状图"),
datazoom_opts=opts.DataZoomOpts(type_="slider"))
)
bar.render_notebook()
- 显示