from pyecharts import options as opts
from pyecharts.charts import Bar
x_axis=["first","second","third","forth","fifth"]
simple_y_axis=[1,2,3,4,5]
simpleBar = (
Bar()
.add_xaxis(x_axis)
.add_yaxis("y_axis_name", simple_y_axis)
.render("simple_bar.html")
)
在添加y轴时传递参数
.add_yaxis("y_axis_name", simple_y_axis,category_gap="80%")
添加如下代码:
.set_global_opts(
xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),
)
在set_global_opts中添加如下选项
title_opts=opts.TitleOpts(title="我是主标题", subtitle="我是副标题"),
render前调用此函数
.reversal_axis()
在set_global_opts中添加如下选项
brush_opts=opts.BrushOpts(),
在添加y坐标的时候,加上一个参数
.add_yaxis("y_axis_name", simple_y_axis,
markpoint_opts=opts.MarkPointOpts(
data=[
opts.MarkPointItem(type_="max", name="最大值"),
opts.MarkPointItem(type_="min", name="最小值"),
opts.MarkPointItem(type_="average", name="平均值"),
]),)
在render之前,加一个函数调用
.set_series_opts(
markline_opts=opts.MarkLineOpts(
data=[
opts.MarkLineItem(type_="min", name="最小值"),
opts.MarkLineItem(type_="max", name="最大值"),
opts.MarkLineItem(type_="average", name="平均值"),
]
),
)
render前调用此函数
.set_series_opts(
markline_opts=opts.MarkLineOpts(
data=[opts.MarkLineItem(y=75, name="yAxis=75")]
),
datazoom_opts=opts.DataZoomOpts(),
yaxis_opts=opts.AxisOpts(
name="水量",
type_="value",
min_=0,
max_=10,
interval=1,
axislabel_opts=opts.LabelOpts(formatter="{value} ml"),# 控制显示格式
splitline_opts=opts.SplitLineOpts(is_show=True),# 显示分割线
),
tooltip_opts=opts.TooltipOpts(
is_show=True, trigger="axis", axis_pointer_type="cross"
),
toolbox_opts=opts.ToolboxOpts(),
显示的工具集是适合当前图像的工具,如果你的图像比较复杂,提供的工具也会更多
from pyecharts import options as opts
from pyecharts.charts import Bar
x_axis=["first","second","third","forth","fifth"]
simple_y_axis=[1,2,3,4,5]
another_simple_y_axis=[2,3,4,5,6]
simpleBar = (
Bar()
.add_xaxis(x_axis)
#这里的两个stack只要相同就行,随便填写内容
.add_yaxis("y_axis_name", simple_y_axis,stack="1")
.add_yaxis("another_y_axis_name", another_simple_y_axis,stack="1")
.set_global_opts(
xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),
)
.render("simple_bar.html")
)
from pyecharts.charts import Bar
x_axis=["first","second","third","forth","fifth"]
# 注意使用字典配置,必须有一个键是value,其他随意
dic_y_axis=[
{"value":1},
{"value":2},
{"value":3},
{"value":4},
{"value":5},
]
c = (
Bar()
.add_xaxis(x_axis)
.add_yaxis("dic_y_axis",dic_y_axis)
.render()
)
效果一样,就不放放图了
from pyecharts.charts import Bar
x_axis=["first","second","third","forth","fifth"]
simple_y_axis=[1,2,3,4,5]
another_y_axis=[2,3,4,5,6]
simpleBar = (
Bar()
.add_xaxis(x_axis)
.add_yaxis("y_axis_name", simple_y_axis)
.add_yaxis("another_y_axis", another_y_axis)
.render()
)
添加y轴的时候传递另外参数
.add_yaxis("y_axis_name", simple_y_axis, gap="0%")
.add_yaxis("another_y_axis", another_y_axis, gap="0%")