我正在创建一个程序,该程序从具有纬度和经度值的数据集中映射船舶的航行。我在“动态更新”部分遇到问题。
我正在用Jupyter(python)进行所有操作,可惜我无法共享我的数据集。我已经尝试根据各种在线指南进行规则的动态matplotlib图绘制,但实际上并没有奏效。我花了很多时间尝试的是xdata和ydata每隔0.1s更新一次的行,但这并不说明我所有绘图都需要套用transform = ccrs.Geodetic的事实。
fig=plt.figure(figsize=[20,10])#create figure with matplotlib
ax1=fig.add_subplot(1,2,1,projection=ccrs.SouthPolarStereo())#add a subplot using the cartopy SouthPolarStereo
fig.subplots_adjust(bottom=0.05, top=0.95,left=0.04, right=0.95, wspace=0.02)#adjust size
ax1.set_extent([-180,180,-180,-55],ccrs.PlateCarree())#show only below 55S lat
ax1.gridlines()
ax1.add_feature(cfeature.LAND)
ax1.add_feature(cfeature.OCEAN)
ax1.coastlines()
#adding some features to the map
#plt.plot("LONVAL","LATVAL",color="green",marker="o",transform=ccrs.Geodetic())
xdata=[]
ydata=[]
#empty x and y data
line,=ax1.plot(xdata,ydata,"r-")#line
for vals in latlong.itertuples():#latlong is a dataframe from my dataset with julian day, latitude and longitude
jday,lat,lon=vals[1],vals[2],vals[3]
xdata.append(lon)
ydata.append(lat)
#append the x and y data with the lat and lon for that iteration
line.set_xdata(xdata)
line.set_ydata(ydata)
plt.draw()
plt.pause(1e-17)
time.sleep(0.1)
#set x and y data and draw it. supposedly.
#plt.plot(lon,lat,color="green",marker="o",transform=ccrs.Geodetic())
#print(lat,lon)
#the above two lines work but just make me a static image.
# print(xdata,ydata)
plt.show()
期望的结果是缓慢绘制线条动画类型的东西,但是它不起作用。