0

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. The longitude and latitude coordinates are the CSV file attached.

Below the is code compiled so far and the map generated:

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]

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? Thanks

Image description: [https://i.stack.imgur.com/07vzp.png]

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

Dayo
  • 7
  • 2

1 Answers1

1

This requires two steps

  1. Read in the csv data to Python. You can do this with numpy or pandas, e.g. weather_stations = pd.read_csv('path_to_file.csv')

  2. Use the matplotlib function scatter on your geoaxes ax_map. You need to tell the geoaxes the coordinate reference system of your input data. It looks like lons and lats, this is the Plate Carree coordinate reference system. You pass this with the kwarg transform

Taking the data we imported in step 1:

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

Callum Rollo
  • 515
  • 3
  • 12
  • Thank you Macros for your response. Your suggestion helps solve the problem. Your answer is consistent with the solution offered on the blog (https://ourcodingclub.github.io/tutorials/pandas-python-intro/#following). The link contain valuable information, I felt it it worth sharing. However, I realized that some of the points were outside of the map boundary and this obviously will affect further analysis. Any suggestion on how to fix this will be well appreciated. – Dayo Dec 20 '20 at 00:04
  • @Dayo The correct way to thank is clicking to accept the answer. You will be rewarded 2 marks. – swatchai Dec 20 '20 at 07:35
  • @swatchai Apologies! I am new here but I am learning fast. Thank you for guiding me right, – Dayo Dec 21 '20 at 20:33