我已经成功地从自然地球站点创建了一张地图(国家边界和海岸线(,但我发现很难将一些气象站的经纬度坐标绘制到地图上。经度和纬度坐标是附加的CSV文件。
下面是迄今为止编译的代码和生成的地图:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as feature
import cartopy.io.shapereader as shapereader
[在此输入图像描述][1]
countries = shapereader.natural_earth(resolution='10m',
category='cultural',
name='admin_0_countries')
# Find the Nigeria boundary polygon.
for country in shapereader.Reader(countries).records():
if country.attributes['SU_A3'] == 'NGA':
nigeria = country.geometry
break
else:
raise ValueError('Unable to find the NGA boundary.')
plt.figure(figsize=(10, 5))
ax_map = plt.axes(projection=ccrs.PlateCarree())
ax_map.set_extent([-1, 19, -1, 17], ccrs.PlateCarree())
ax_map.add_feature(feature.COASTLINE, linewidth=.5)
ax_map.add_geometries([nigeria], ccrs.Geodetic(), edgecolor='0.8',
facecolor='none')
grid_lines = ax_map.gridlines(draw_labels=True)
plt.show()
请告诉我如何在生成的地图上绘制CSV文件上的坐标?感谢
图像描述:[https://i.stack.imgur.com/07vzp.png]
CSV文件链接:[https://drive.google.com/file/d/152UTebTc_sDbyKDXV3g52jYiVG4n6LEx/view?usp=sharing]
这需要两个步骤
-
将csv数据读入Python。您可以使用numpy或panda来完成此操作,例如
weather_stations = pd.read_csv('path_to_file.csv')
-
使用matplotlib函数分散在地理轴
ax_map
上。您需要告诉地理轴输入数据的坐标参考系。它看起来像lons和lats,这是Plate-Carree坐标参考系。你用夸尔格transform
通过这个
获取我们在步骤1:中导入的数据
ax_map.scatter(weather_stations['LONG'], weather_stations['LAT'], transform=ccrs.PlateCarree())