from pyecharts import options as opts
from pyecharts.charts import Bar,Timeline
from pyecharts.faker import Faker
import random
import pandas as pd
import numpy as np
# 受这篇文章启发https://blog.csdn.net/weixin_42512684/article/details/108176613
data = np.array([random.randint(30,150) for i in range(52*7) ]).reshape(52,7)
df = pd.DataFrame(data,index=[i for i in range(1969,2021)],columns = random.sample(attr, len(attr)))
df
df_sorted = [r[:].sort_values() for i,r in df.iterrows()]
df_sorted[0].values
t1 = Timeline()# 创建 Timeline对象
for j in range(1969,2021):
bar = (
Bar()
.add_xaxis([str(i) for i in df_sorted[j-1969].index])
.add_yaxis('Data',[int(i) for i in df_sorted[j-1969].values]
,label_opts = opts.LabelOpts(position = 'right'),
)
.set_series_opts(label_opts = opts.LabelOpts(is_show = True,position = 'right'))
.reversal_axis()
.set_global_opts(title_opts = opts.TitleOpts("{}".format(j),
pos_left = '50%',
),
legend_opts = opts.LegendOpts(pos_right = '10%'))
)
t1.add(bar,'{}年'.format(j))
t1.add_schema(
symbol = 'arrow',# 设置标记时间;
#orient = 'vertical',
symbol_size = 2,# 标记大小;
play_interval = 1000,# 播放时间间隔;
control_position = 'right',# 控制位置;
linestyle_opts = opts.LineStyleOpts(width = 5,
type_ = 'dashed',
color = 'rgb(255,0,0,0.5)'),
label_opts = opts.LabelOpts(color = 'rgb(0,0,255,0.5)',
font_size = 15,
font_style = 'italic',
font_weight = 'bold',
font_family ='Time New Roman',
position = 'left',
interval = 20,
)
)
t1.render_notebook()