from pyecharts.charts import Bar,Line
import pyecharts.options as opts
x_data = ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
bar = (
Bar()
.add_xaxis(xaxis_data=x_data)
.add_yaxis(
series_name="蒸发量",
y_axis=[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
label_opts=opts.LabelOpts(is_show=False),
)
.add_yaxis(
series_name="降水量",
y_axis=[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
label_opts=opts.LabelOpts(is_show=False),
)
.extend_axis(
yaxis=opts.AxisOpts(
name="温度",
type_="value",
min_=0,
max_=25,
interval=5,
axislabel_opts=opts.LabelOpts(formatter="{value} °C"),
)
)
.set_global_opts(
tooltip_opts=opts.TooltipOpts(
is_show=True, trigger="axis", axis_pointer_type="cross"
#鼠标移至该点时,横向虚线显示
),
xaxis_opts=opts.AxisOpts(
type_="category",
axispointer_opts=opts.AxisPointerOpts(is_show=True, type_="shadow"),
#鼠标移至某点时,竖趟阴影显示。
),
yaxis_opts=opts.AxisOpts(
name="水量",
type_="value",
min_=0, #y轴最小值
max_=250, #y轴最大值
interval=50, #y轴刻度
axislabel_opts=opts.LabelOpts(formatter="{value} ml"), # y轴坐标显示
axistick_opts=opts.AxisTickOpts(is_show=True),
splitline_opts=opts.SplitLineOpts(is_show=True),
),
)
)
line = (
Line()
.add_xaxis(xaxis_data=x_data)
.add_yaxis(
series_name="平均温度",
yaxis_index=1, #y轴索引,即折线图用哪一个y轴, y轴从左至右的索引值为0,1,2……,即水量y轴索引为0,温度y轴索引为1
y_axis=[2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2],
label_opts=opts.LabelOpts(is_show=False), #折线图上点的附近否显示数据
)
)
bar.overlap(line).render("mixed_bar_and_line.html")
bar.overlap(line).render_notebook()
pyecharts 交互性(条形+折线统计图)
于 2023-07-24 13:24:17 首次发布