14

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

Ray Bell
  • 1,508
  • 4
  • 18
  • 45

2 Answers2

26

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.

ajdawson
  • 3,183
  • 27
  • 36
3

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

  • 1
    Thanks. Good to know I can pick up some of the matplotlib functions in cartopy. Yes. Adding the ax.set_ylim([0, 80]) got me what what I wanted plt.figure(figsize=(5.12985642927, 3)) ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=-35)) ax.set_extent([-100, 30, 0, 80]) ax.set_ylim([0, 80]) ax.coastlines(resolution='110m') gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=2, color='gray', alpha=0.5, linestyle='--') http://imgur.com/a/JYzEm – Ray Bell Apr 18 '17 at 15:01