CephaloRhod
CephaloRhod

Reputation: 75

Plotting latitude / longitude from Excel spreadsheet using Cartopy

Trying to plot a survey transect on a map using Cartopy, a library seriously lacking in online information compared to others. My lat/long data is in two seperate columns of an Excel spreadsheet.

I have managed to build a basemap, and my script for that is as follows:

import cartopy.feature as cf

map = plt.figure(figsize=(15,15))
ax = plt.axes(projection=ccrs.EuroPP())
ax.coastlines(resolution='10m')

ax.add_feature(cf.LAND)
ax.add_feature(cf.OCEAN)
ax.add_feature(cf.COASTLINE)
ax.add_feature(cf.BORDERS, linestyle=':')
ax.add_feature(cf.LAKES, alpha=0.5)
ax.add_feature(cf.RIVERS)

ax.stock_img()

Producing the following figure figure

I have also read in the data from Excel columns labeled 'latitude' (column 'L') and 'longitude' (column 'M') using pandas, from the following spreadsheet: https://liveplymouthac-my.sharepoint.com/:x:/g/personal/rhodri_irranca-davies_postgrad_plymouth_ac_uk/EYGoEUAO8tBLkdT0r4dwDdsBAijsVChsLCec-DxaYo2Tew?e=rs9cBc

This was done using the following code:

file = r'C:\Users\Laptop\Documents\Python\Thesis\t2_GeoData.xlsx'
df_lat = pd.read_excel(file, index_col=None, na_values=['NA'], usecols = 'L')
df_lon = pd.read_excel(file, index_col=None, na_values=['NA'], usecols = 'M')

Was pandas the right option? If so, how do I now incorporate the two dataframes created ('df_lat' and 'df_lon') and plot them as transects using cartopy?

Thanks in advance :)

Upvotes: 1

Views: 1128

Answers (1)

DopplerShift
DopplerShift

Reputation: 5843

I'm not sure what you mean exactly as plot them as transects, but you can plot lon/lat lines in CartoPy with:

ax.plot(df_lon, df_lat, linestyle='-', color='orange', transform=ccrs.PlateCarree())

Upvotes: 1

Related Questions