import pandas as pd
df = pd.DataFrame({
'year': [2014, 2015, 2016, 2014, 2015, 2016, 2014, 2015, 2016],
'province': ['广东省', '广东省', '河南省',
'湖南省', '北京市', '北京市',
'上海市', '新疆维吾尔自治区', '上海市'],
'values': [100, 150, 75,
120, 80, 200,
110, 200, 190]
})
from pyecharts import options as opts
from pyecharts.charts import Map, Timeline
from pyecharts.globals import ChartType, SymbolType, CurrentConfig, NotebookType
CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB
grouped_df = df.groupby('year')
t = Timeline()
for year, year_df in grouped_df:
map_chart = (
Map()
.add("商家A", year_df[['province', 'values']].values, "china")
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
title_opts=opts.TitleOpts(title=f"Map-{year}年某些数据"),
visualmap_opts=opts.VisualMapOpts(max_=df['values'].quantile()),
)
)
print(year_df[['province', 'values']].values.tolist())
t.add(map_chart, "{}年".format(year))
t.render_notebook()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33