Search code examples
pythoncartopy

Cartopy plotting extra points at poles when passed one at a time


When plotting an orthographic projection with some points on the other side of the globe, how come the first approach plots as expected, but the second takes all the points that would be on the other side of the globe and plots them at the pole of the projection? Is there a solution beyond filtering out the points that are out of sight, and if not what is the best way to do that for a pole at an arbitrary lon/lat (as opposed to the north pole, which is relatively trivial)?

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

projection = ccrs.Orthographic(0, 90)
transform = ccrs.Geodetic()

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection = projection)

ax.coastlines()
ax.set_global()
ax.gridlines()

npoints = 100
np.random.seed(71077345)
lon = np.random.sample(npoints) * 360
lat = np.random.sample(npoints) * 180 - 90
plt.plot(lon,
         lat,
         'ro',
         alpha = 0.3,
         transform = transform)

for i in range(npoints):
    plt.plot(lon[i],
             lat[i],
             'b.',
             alpha = 0.3,
             transform = transform)

example with extra points at the pole


Solution

  • This bug has been fixed in v0.19 and beyond by #1710.