繁体   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?

我已经从自然地球站点成功创建了 map(国家边界和海岸线),但我发现很难将 plot 气象站的经纬度坐标转换为 Z1D78DC8ED51214E518B5114AE2449。 经纬度坐标为附件 CSV 文件。

下面是到目前为止编译的代码和生成的 map:

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()

我如何 plot CSV 文件上的坐标 map 生成,好吗? 谢谢

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

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

这需要两个步骤

  1. 将 csv 数据读入 Python。 您可以使用numpypandas来执行此操作,例如weather_stations = pd.read_csv('path_to_file.csv')

  2. 在地理轴 ax_map 上使用 matplotlib ax_map 散点图 您需要告诉 geoaxes 输入数据的坐标参考系统。 它看起来像 lons 和 lats,这是 Plate Carree 坐标参考系。 你通过 kwarg transform传递它

获取我们在步骤 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