实现功能:将轨迹数据可视化到地图上
适用范围:车辆、船舶 等含有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