Matplotlib底图未在正确位置打印点

2024-04-20 01:48:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图在一个基本地图上绘制飓风路径的经纬度点。目前,我正在研究一个单一的飓风路径的概念证明,然后再扩大规模。但是,当我绘制这些点时,它们并没有正确地绘制在底图上相应的纬度/经度位置。你知道吗

from mpl_toolkits.basemap import Basemap
from netCDF4 import Dataset as NetCDFFile
import cartopy
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
from datetime import datetime
from datetime import timedelta
import matplotlib
matplotlib.use("Agg")


#Data was already parsed from a text file and not relevant.

data = np.array(data)


m = Basemap(projection='cyl',area_thresh=10000, llcrnrlat=-90,urcrnrlat=90,llcrnrlon=-180,urcrnrlon=180,resolution='c')
parallels = np.arange(-90.,105.,15.)
meridians = np.arange(-180.,180.,30.)
m.drawparallels(parallels,labels=[1,0,0,0],labelstyle="+/-", linewidth=.1, fontsize=6)
m.drawmeridians(meridians,labels=[0,0,0,1],labelstyle="+/-", linewidth=.1, fontsize=6)
m.drawcoastlines(linewidth=0.25)
m.drawlsmask(land_color='Linen', ocean_color='White')


data_traj = data[0]

lat = [i[1] for i in data_traj]
lon = [i[0] for i in data_traj]

x,y = m(lon, lat)

m.plot(x,y,'-', markersize=0.25, linewidth=0.25)
plt.show()
plt.savefig('trajectories.png',dpi=1200)

以下是数据集[0]中的一个示例:

经度|纬度|速度|气压|年|月|日|时

array([['145.83', '50.82', '25.77', '1012.17', '2015', '10', '11', '15'],
       ['147.23', '51.52', '20.23', '1012.76', '2015', '10', '11', '18'],
       ['147.38', '51.52', '19.17', '1013.27', '2015', '10', '11', '21'],
       ['146.11', '51.38', '21.39', '1014.98', '2015', '10', '12', '0'],
       ['147.66', '50.82', '21.63', '1014.29', '2015', '10', '12', '3'],
       ['148.08', '51.80', '24.23', '1014.36', '2015', '10', '12', '6'],
       ['147.66', '51.52', '23.05', '1016.09', '2015', '10', '12', '9'],
       ['145.55', '51.10', '19.20', '1018.02', '2015', '10', '12', '12'],
       ['146.11', '51.38', '13.89', '1017.91', '2015', '10', '12', '15'],
       ['147.66', '51.38', '17.05', '1018.65', '2015', '10', '12', '18'],
       ['147.38', '51.52', '14.72', '1018.93', '2015', '10', '12', '21'],
       ['146.11', '51.52', '15.04', '1020.68', '2015', '10', '13', '0'],
       ['146.39', '51.52', '20.42', '1022.26', '2015', '10', '13', '3'],
       ['146.95', '51.66', '17.22', '1022.93', '2015', '10', '13', '6'],
       ['147.94', '51.80', '19.31', '1023.04', '2015', '10', '13', '9'],
       ['146.25', '51.52', '19.36', '1023.79', '2015', '10', '13', '12'],
       ['145.97', '51.38', '15.85', '1024.03', '2015', '10', '13', '15'],
       ['147.66', '51.52', '15.86', '1023.97', '2015', '10', '13', '18'],
       ['149.06', '51.66', '15.50', '1023.67', '2015', '10', '13', '21'],
       ['148.08', '52.36', '17.53', '1023.14', '2015', '10', '14', '0'],
       ['146.11', '51.52', '18.49', '1022.46', '2015', '10', '14', '3'],
       ['146.11', '51.52', '21.94', '1022.35', '2015', '10', '14', '6'],
       ['147.94', '51.80', '20.82', '1022.43', '2015', '10', '14', '9'],
       ['147.94', '51.80', '21.42', '1023.85', '2015', '10', '14', '12'],
       ['147.66', '51.66', '21.25', '1024.46', '2015', '10', '14', '15'],
       ['145.97', '51.10', '18.61', '1025.31', '2015', '10', '14', '18'],
       ['145.83', '50.82', '18.43', '1025.44', '2015', '10', '14', '21'],
       ['145.83', '50.82', '16.71', '1025.31', '2015', '10', '15', '0'],
       ['145.83', '50.82', '17.23', '1025.01', '2015', '10', '15', '3'],
       ['145.83', '50.82', '14.52', '1024.28', '2015', '10', '15', '6'],
       ['145.83', '50.82', '14.67', '1023.76', '2015', '10', '15', '9'],
       ['146.95', '50.96', '15.17', '1026.03', '2015', '10', '15', '12'],
       ['148.64', '51.66', '14.18', '1027.24', '2015', '10', '15', '15'],
       ['146.53', '51.38', '12.57', '1025.30', '2015', '10', '15', '18'],
       ['146.67', '51.38', '17.03', '1024.89', '2015', '10', '15', '21'],
       ['145.83', '50.82', '18.64', '1024.58', '2015', '10', '16', '0']],
      dtype='<U7')

样本输出:

https://i.stack.imgur.com/3AuGw.jpg

编辑:找到错误。你知道吗


Tags: fromimport路径datadatetimematplotlibasnp