@@ -85,7 +85,7 @@ def geo_bin_from_array(array_sub, geo_coord, var_name, title, pop_name=True,
8585 axis .set_extent ((extent ))
8686 add_shapes (axis )
8787 if pop_name :
88- add_populated (axis , extent )
88+ add_populated_places (axis , extent )
8989
9090 if 'gridsize' not in kwargs :
9191 kwargs ['gridsize' ] = min (int (array_im .size / 2 ), MAX_BINS )
@@ -158,9 +158,9 @@ def geo_im_from_array(array_sub, geo_coord, var_name, title, **kwargs):
158158 # Create colormesh, colorbar and labels in axis
159159 cbax = make_axes_locatable (axis ).append_axes ('right' , size = "6.5%" , \
160160 pad = 0.1 , axes_class = plt .Axes )
161- cbar = plt .colorbar ( \
162- axis . pcolormesh ( grid_x , grid_y , np . squeeze ( grid_im ), ** kwargs ),
163- cax = cbax , orientation = 'vertical' )
161+ cbar = plt .colorbar (axis . pcolormesh ( grid_x , grid_y , \
162+ np . squeeze ( grid_im ), transform = ccrs . PlateCarree ( ), ** kwargs ), \
163+ cax = cbax , orientation = 'vertical' )
164164 cbar .set_label (name )
165165 axis .set_title (tit )
166166
@@ -328,12 +328,12 @@ def add_shapes(axis, projection=ccrs.PlateCarree()):
328328 axis .add_geometries ([geometry ], projection , facecolor = '' , \
329329 edgecolor = 'black' )
330330
331- def add_populated (axis , extent , projection = ccrs .PlateCarree ()):
331+ def add_populated_places (axis , extent , projection = ccrs .PlateCarree ()):
332332 """Add city names.
333333
334334 Parameters:
335335 axis (cartopy.mpl.geoaxes.GeoAxesSubplot): cartopy axis.
336- extent (): geographical limits.
336+ extent (list ): geographical limits.
337337 projection (cartopy.crs projection, optional): geographical projection,
338338 PlateCarree default.
339339
@@ -342,9 +342,7 @@ def add_populated(axis, extent, projection=ccrs.PlateCarree()):
342342 category = 'cultural' , name = 'populated_places_simple' )
343343
344344 shp = shapereader .Reader (shp_file )
345- cnt = 0
346345 for rec , point in zip (shp .records (), shp .geometries ()):
347- cnt += 1
348346 if (point .x <= extent [1 ]) and (point .x > extent [0 ]):
349347 if (point .y <= extent [3 ]) and (point .y > extent [2 ]):
350348 axis .plot (point .x , point .y , 'ko' , markersize = 7 , \
@@ -353,6 +351,30 @@ def add_populated(axis, extent, projection=ccrs.PlateCarree()):
353351 horizontalalignment = 'right' , verticalalignment = 'bottom' , \
354352 transform = projection , fontsize = 14 )
355353
354+ def add_cntry_names (axis , extent , projection = ccrs .PlateCarree ()):
355+ """Add country names.
356+
357+ Parameters:
358+ axis (cartopy.mpl.geoaxes.GeoAxesSubplot): cartopy axis.
359+ extent (list): geographical limits.
360+ projection (cartopy.crs projection, optional): geographical projection,
361+ PlateCarree default.
362+
363+ """
364+ shp_file = shapereader .natural_earth (resolution = '10m' , \
365+ category = 'cultural' , name = 'admin_0_countries' )
366+
367+ shp = shapereader .Reader (shp_file )
368+ for rec , point in zip (shp .records (), shp .geometries ()):
369+ point_x = point .centroid .xy [0 ][0 ]
370+ point_y = point .centroid .xy [1 ][0 ]
371+ if (point_x <= extent [1 ]) and (point_x > extent [0 ]):
372+ if (point_y <= extent [3 ]) and (point_y > extent [2 ]):
373+ if 'Sint' not in rec .attributes ['NAME' ]:
374+ axis .text (point_x , point_y , rec .attributes ['NAME' ], \
375+ horizontalalignment = 'center' , verticalalignment = 'center' , \
376+ transform = projection , fontsize = 14 )
377+
356378def get_row_col_size (num_sub ):
357379 """Compute number of rows and columns of subplots in figure.
358380
0 commit comments