分类: Python/Ruby
2022-07-08 17:17:12
# 背景色
background_color_js = (
"new echarts.graphic.LinearGradient(0, 0, 0, 1, "
"[{offset: 0, color: '#c86589'}, {offset: 1, color: '#06a7ff'}], false)"
)
# 线条样式
linestyle_dic = { 'normal': {
'width': 4,
'shadowColor': '#696969',
'shadowBlur': 10,
'shadowOffsetY': 10,
'shadowOffsetX': 10,
}
}
timeline = Timeline(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js),
width='980px',height='600px'))
bj, gz, sh, sz= [], [], [], []
all_max = []
x_data = data_10[data_10['城市'] == '北京']['日'].tolist()
for d_time in跟单网gendan5.com range(len(x_data)):
bj.append(data_10[(data_10['日'] == x_data[d_time]) & (data_10['城市']=='北京')]["最高温度"].values.tolist()[0])
gz.append(data_10[(data_10['日'] == x_data[d_time]) & (data_10['城市']=='广州')]["最高温度"].values.tolist()[0])
sh.append(data_10[(data_10['日'] == x_data[d_time]) & (data_10['城市']=='上海')]["最高温度"].values.tolist()[0])
sz.append(data_10[(data_10['日'] == x_data[d_time]) & (data_10['城市']=='深圳')]["最高温度"].values.tolist()[0])
line = (
Line(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js),
width='980px',height='600px'))
.add_xaxis(
x_data,
)
.add_yaxis(
'北京',
bj,
symbol_size=5,
is_smooth=True,
is_hover_animation=True,
label_opts=opts.LabelOpts(is_show=False),
)
.add_yaxis(
'广州',
gz,
symbol_size=5,
is_smooth=True,
is_hover_animation=True,
label_opts=opts.LabelOpts(is_show=False),
)
.add_yaxis(
'上海',
sh,
symbol_size=5,
is_smooth=True,
is_hover_animation=True,
label_opts=opts.LabelOpts(is_show=False),
)
.add_yaxis(
'深圳',
sz,
symbol_size=5,
is_smooth=True,
is_hover_animation=True,
label_opts=opts.LabelOpts(is_show=False),
)
.set_series_opts(linestyle_opts=linestyle_dic)
.set_global_opts(
title_opts=opts.TitleOpts(
title='北上广深10月份最高气温变化趋势',
pos_left='center',
pos_top='2%',
title_textstyle_opts=opts.TextStyleOpts(color='#DC143C', font_size=20)),
tooltip_opts=opts.TooltipOpts(
trigger="axis",
axis_pointer_type="cross",
background_color="rgba(245, 245, 245, 0.8)",
border_width=1,
border_color="#ccc",
textstyle_opts=opts.TextStyleOpts(color="#000"),
),
xaxis_opts=opts.AxisOpts(
# axislabel_opts=opts.LabelOpts(font_size=14, color='red'),
# axisline_opts=opts.AxisLineOpts(is_show=True,
# linestyle_opts=opts.LineStyleOpts(width=2, color='#DB7093'))
is_show = False
),
# 资料、解答、教程可加Q :261823976免费领
yaxis_opts=opts.AxisOpts(
name='最高气温',
is_scale=True,
# min_= int(min([gz[d_time],sh[d_time],sz[d_time],bj[d_time]])) - 10,
max_= int(max([gz[d_time],sh[d_time],sz[d_time],bj[d_time]])) + 10,
name_textstyle_opts=opts.TextStyleOpts(font_size=16,font_weight='bold',color='#5470c6'),
axislabel_opts=opts.LabelOpts(font_size=13,color='#5470c6'),
splitline_opts=opts.SplitLineOpts(is_show=True,
linestyle_opts=opts.LineStyleOpts(type_='dashed')),
axisline_opts=opts.AxisLineOpts(is_show=True,
linestyle_opts=opts.LineStyleOpts(width=2, color='#5470c6'))
),
legend_opts=opts.LegendOpts(is_show=True, pos_right='1%', pos_top='2%',
legend_icon='roundRect',orient = 'vertical'),
))
timeline.add(line, '{}'.format(x_data[d_time]))
timeline.add_schema(
play_interval=1000, # 轮播速度
is_timeline_show=True, # 是否显示 timeline 组件
is_auto_play=True, # 是否自动播放
pos_left="0",
pos_right="0"
)
timeline.render_notebook()