我已经成功地从自然地球站点创建了一个地图(国家边界和海岸线),但是我发现很难在地图上绘制天气的经度和纬度坐标。经度和纬度坐标是附加的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或pandas进行此操作,例如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())
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句