Search code examples
pythonscatter-plotcartopy

why the scatter plot can not be on the map created by cartopy


plt.figure(figsize = (10,10),dpi =150)
ax = plt.axes(projection=ccrs.EuroPP())

ax.coastlines(resolution='50m')
ax.set_extent([-16., 5., 49., 61.])


plt.scatter([10.,15.],[52.5,55.],marker='o',s = 100,
            transform = ccrs.EuroPP(), color = "red")

ax.gridlines(draw_labels=True)
plt.show()

Why there is only a map, and the scatter plot cannot be on the map?


Solution

  • The transform you specify for the scatter should be the projection of the data, not the map. It looks as if they are lat/lon values (epsg:4326)? (Technically they could of course be EuroPP coordinates, just really close to the origin)

    Where do you expect those points to be more or less?

    map_proj = ccrs.EuroPP()
    data_proj = ccrs.PlateCarree()
    
    fig, ax = plt.subplots(
        figsize=(10,10), dpi=76, 
        subplot_kw=dict(projection=map_proj),
    )
    
    ax.scatter(
        [10.,15.],[52.5,55.], marker='o', s=100, 
        color="r", transform=data_proj,
    )
    
    ax.coastlines(resolution='50m')
    ax.set_extent([-5., 20., 49., 61.], crs=data_proj)
    ax.gridlines(draw_labels=True)
    

    enter image description here