Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cartopy - set_extent() extending requested boundary

Tags:

cartopy

i'm new to cartopy and still learning basic features.

I tried to plot a specific region however, cartopy extended this region and produced a map going up to approximately 85oN when I requested 80oN. Is there a way I can ensure I only get the region I am interested in?

plt.figure(figsize=(5.12985642927, 3))
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=-35))
ax.set_extent([-100, 30, 0, 80])
ax.coastlines(resolution='110m')
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
              linewidth=2, color='gray', alpha=0.5, linestyle='--')

PC regional map

like image 860
Ray Bell Avatar asked Apr 18 '17 10:04

Ray Bell


2 Answers

You should make sure to tell the set_extent method what coordinate system you are specifying the extents in, in this case:

ax.set_extent([-100, 30, 0, 80], crs=ccrs.PlateCarree())

This method is preferred in cartopy because it avoids having to use the set_xlim/set_ylim which always operate in projection coordinates, which can be the cause of much confusion when working with projections other than PlateCarree(). Using set_extent with an explicit crs will always do what you expect regardless of the projection of your plot.

like image 185
ajdawson Avatar answered Nov 16 '22 17:11

ajdawson


have you tried ax.set_xlim to set the upper and lower limits of the x-axis? Here are some usage examples and instructions.

like image 2
Corinne Bosley Avatar answered Nov 16 '22 16:11

Corinne Bosley