简体   繁体   English

我如何使用 cartopy 和 ZF620113237AEEZ56E 来自“natural_earth”的 map 上的 csv 中的 plot 坐标?

[英]How do I plot coordinates in csv on the map from from 'natural_earth" using cartopy and matplotlib?

I have successfully created a map (country boundary and coastline) from natural earth site but I am finding it difficult to plot the longitude and latitude coordinates of weather some stations to the map.我已经从自然地球站点成功创建了 map(国家边界和海岸线),但我发现很难将 plot 气象站的经纬度坐标转换为 Z1D78DC8ED51214E518B5114AE2449。 The longitude and latitude coordinates are the CSV file attached.经纬度坐标为附件 CSV 文件。

Below the is code compiled so far and the map generated:下面是到目前为止编译的代码和生成的 map:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as feature
import cartopy.io.shapereader as shapereader

[enter image description here][1] [在此处输入图片描述][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()

How do I plot the coordinates on the CSV file on the map generated, please?我如何 plot CSV 文件上的坐标 map 生成,好吗? Thanks谢谢

Image description: [https://i.stack.imgur.com/07vzp.png]图片说明:[https://i.stack.imgur.com/07vzp.png]

link to CSV file: [https://drive.google.com/file/d/152UTebTc_sDbyKDXV3g52jYiVG4n6LEx/view?usp=sharing]链接到 CSV 文件:[https://drive.google.com/file/d/152UTebTc_sDbyKDXV3g52jYiVG4n6LEx/view?usp=sharing]

This requires two steps这需要两个步骤

  1. Read in the csv data to Python.将 csv 数据读入 Python。 You can do this with numpy or pandas , eg weather_stations = pd.read_csv('path_to_file.csv')您可以使用numpypandas来执行此操作,例如weather_stations = pd.read_csv('path_to_file.csv')

  2. Use the matplotlib function scatter on your geoaxes ax_map .在地理轴 ax_map 上使用 matplotlib ax_map 散点图 You need to tell the geoaxes the coordinate reference system of your input data.您需要告诉 geoaxes 输入数据的坐标参考系统。 It looks like lons and lats, this is the Plate Carree coordinate reference system.它看起来像 lons 和 lats,这是 Plate Carree 坐标参考系。 You pass this with the kwarg transform你通过 kwarg transform传递它

Taking the data we imported in step 1:获取我们在步骤 1 中导入的数据:

ax_map.scatter(weather_stations['LONG'], weather_stations['LAT'], transform=ccrs.PlateCarree())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM