1

I have a Nx2 matrix of lat lon coordinate pairs, spatial_data, and I have an array of measurements at these coordinates.

I would like to plot this data on a globe, and I understand that Basemap can do this. I found this link which shows how to plot data if you have cartesian coordinates. Does there exist functionality to convert lat,lon to cartesian coordinates? Alternatively, is there a way to plot this data with only the lat,lon information?

Community
  • 1
  • 1
user3600497
  • 1,621
  • 1
  • 18
  • 22

1 Answers1

2

You can use cartopy:

import numpy as np
import matplotlib.pyplot as plt
from cartopy import crs

# a grid for the longitudes and latitudes
lats = np.linspace(-90, 90, 50)
longs = np.linspace(-180, 180, 50)
lats, longs = np.meshgrid(lats, longs)

# some data
data = lats[1:] ** 2 + longs[1:] ** 2

fig = plt.figure()

# create a new axes with a cartopy.crs projection instance
ax = fig.add_subplot(1, 1, 1, projection=crs.Mollweide())

# plot the date
ax.pcolormesh(
    longs, lats, data,
    cmap='hot',
    transform=crs.PlateCarree(),  # this means that x, y are given as longitude and latitude in degrees
)
fig.tight_layout()
fig.savefig('cartopy.png', dpi=300)

Result: result

MaxNoe
  • 14,470
  • 3
  • 41
  • 46