更新:
最近又发现了更好用的工具keplergl,基本不需要写代码,拿着数据拆箱即用。
欢迎访问我的这篇博客:酷炫Keplergl
实现功能:将轨迹数据可视化到地图上
适用范围:车辆、船舶 等含有GPS定位系统的均可
编程语言:python
效果展示:
数据说明:需要”经度“和”纬度“这两列的信息。【63627.csv】
注:如果是西经、南纬,需要是负值哦~
代码实现:
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import rcParams
import cartopy.feature as cf
import cartopy.crs as ccrs
from cartopy.mpl.ticker import LongitudeFormatter,LatitudeFormatter
rcParams['font.family']=rcParams['font.sans-serif']='SimHei' #font.family局部字体,font.sans-serif全局字体
df=pd.read_csv(r'C:\Users\admin\Desktop\63627.csv')
fig1=plt.figure()
lon1,lon2,lat1,lat2=119,128,23,35 #最小经度,最大经度,最小纬度,最大纬度
#绘制底图
ax=plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([lon1,lon2,lat1,lat2],crs=ccrs.PlateCarree()) #设置地图展示的范围
ax.add_feature(cf.COASTLINE,lw=0.3)
ax.add_feature(cf.LAND)
ax.add_feature(cf.OCEAN)
ax.add_feature(cf.RIVERS)
#绘制船舶轨迹
sns.scatterplot(data=df,x='longitude',y='latitude',s=1,color='orangered')
#设置x、y轴的刻度
ax.set_xticks(np.arange(lon1,lon2,2))
ax.set_yticks(np.arange(lat1,lat2,2))
lon_formatter=LongitudeFormatter(zero_direction_label=False)
lat_formatter=LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
#设置标题和坐标轴名称
plt.title('轨迹可视化')
plt.xlabel("经度")
plt.ylabel('纬度')
plt.show()
更多的功能可以参考官网:Cartopy