python(pyecharts)生成国家轨迹图
2020-12-13 本文已影响0人
小王同学123321
原始数据保存在excel中,格式是:

代码如下:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import pandas as pd
from pyecharts import options
from pyecharts.charts import Geo
from pyecharts.globals import ChartType, SymbolType, CurrentConfig,OnlineHostType
# 链式调用
def createhtml():
try:
df=pd.read_excel("../data/data.xlsx",sheet_name=0)
datarows=df.shape[0]
citylist,citybeizhulist=[],[]
for i in range(datarows):
citylist.append(list(df.loc[i].tolist()[:2]))
sourcecity=df.loc[i].tolist()[0]
beizhu=df.loc[i].tolist()[2]
citybeizhulist.append([sourcecity,beizhu])
c = (
Geo()
.add_schema(maptype="china",
itemstyle_opts=options.ItemStyleOpts(color="#F2F2F2", border_color="#81F7F3"),
label_opts=options.LabelOpts(is_show=True))
.add("",
citybeizhulist,
type_=ChartType.EFFECT_SCATTER,
color="#58FA82",
)
.add("",
citylist,
type_=ChartType.LINES,
effect_opts=options.EffectOpts(symbol=SymbolType.ARROW,symbol_size=6,color="blue"),
linestyle_opts=options.LineStyleOpts(curve=0.2),
)
.set_series_opts(label_opts=options.LabelOpts(is_show=False))
.set_global_opts(title_opts=options.TitleOpts(title="动态轨迹图"))
.render("../result/geo_lines_background.html")
)
print("Congratulations on your success!!!")
except Exception as e:
print("failed,{0}".format(e))
input('程序执行失败,按任意键退出:')
if __name__ == '__main__':
createhtml()
input("回车键退出.")
输出html结果为:
