While it's possible to make a map plot by either:
crs = area_def.to_cartopy_crs()
ax = plt.axes(projection=crs)
ax.background_img(name='BM')
plt.imshow(result, transform=crs, extent=crs.bounds, origin='upper', cmap='RdBu_r')
or
sst = dataset.variables['sst'][0, :, :]
lats = dataset.variables['lat'][:]
lons = dataset.variables['lon'][:]
ax = plt.axes(projection=ccrs.PlateCarree())
plt.contourf(lons, lats, sst, 60,
transform=ccrs.PlateCarree())
The first needs a crs object. And the second only works for filled contour plots. Is there a way get an imshow map plot with three arrays, data, lats, and lons.
Although you have
cartopy
in your tags, I think what you are trying to achieve can be solved with geopandas. The important concept is to have the same CRS as you plot your points in the figure so that all information align.Lets look at a simple example
Note: Since we want to plot the cities on the same map we use the same figure Axes
ax
. Also note that bothworld
andcities
have the sameCRS
. You can see this by doingBoth return
epsg:4326
, so sameCRS
.Now, you have a new set of points you want to add to your plot. Let's create a few random points.
Here we create random points between lon [30, 40] east and lat [10, 30] south. Note that I am copying the
crs
ofworld
since it isepsg:4326
.If it was something else, we would initialise
my_points
withcrs='epsg:4326'
and then translatemy_points
toworld.crs
as followsFinally we can plot on the same Axes
For more, visit this page