这周学习了python的地图可视化库Folium,成功运用不同颜色将轨迹显示出来
import folium
import re
f = open("C:\\Users\\容错率\\Desktop\\轨迹数据\\release\\taxi_log_2008_by_id\\1.txt") # 返回一个文件对象
line = f.readline() # 调用文件的 readline()方法
res=[]
while line:
# print(line) # 后面跟 ',' 将忽略换行符
#print(line, end = '') # 在 Python 3 中使用
line=line.replace(","," ")
# print(line)
list=re.split(' ',line)
# print(len(list))
te=[]
te.append(float(list[4]))
te.append(float(list[3]))
res.append(te)
line = f.readline()
f.close()
m = folium.Map(location=[39.86,116.55],
zoom_start=10,
control_scale=True)
ls = folium.PolyLine(locations=res,weight=1,
color='blue')
ls.add_to(m)
f = open("C:\\Users\\容错率\\Desktop\\轨迹数据\\release\\taxi_log_2008_by_id\\2.txt") # 返回一个文件对象
line = f.readline() # 调用文件的 readline()方法
res=[]
while line:
# print(line) # 后面跟 ',' 将忽略换行符
#print(line, end = '') # 在 Python 3 中使用
line=line.replace(","," ")
# print(line)
list=re.split(' ',line)
# print(len(list))
te=[]
te.append(float(list[4]))
te.append(float(list[3]))
res.append(te)
line = f.readline()
f.close()
ls = folium.PolyLine(locations=res,weight=1,
color='red')
ls.add_to(m)
m