Reputation: 20185
import matplotlib.pyplot as plt
from cartopy import crs as ccrs, feature as cfeature
import cartopy.io.shapereader as shpreader
fig = plt.figure(figsize=(11, 11))
ax = plt.subplot(1, 1, 1, projection=ccrs.PlateCarree(central_longitude=0))
ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=1, color='gray', alpha=0.5, linestyle='--')
extent = (-180, 0, 0, 60) # Define the extent as (min_lon, max_lon, min_lat, max_lat)
ax.set_extent(extent)
ax.add_feature(cfeature.LAND , linewidth=0.5, edgecolor='black')
returns (as I would expect)
As far as I understand, the extent
extent = (-180, 60, 0, 60)
should limit the scope to the 60 degree east (indicated by the red line) but it doesn't:
What am I doing wrong?
Upvotes: 0
Views: 376
Reputation: 64463
Are you sure the first image is returned as you expect? Given that you specify the maximum latitude to be 60°, and the map ranges up to ~90°.
As the docstring for set_extent
mentions, if you omit the projection of your extent, it assumes a Geodetic version.
So in your case, you want to be explicit (which is good practice anyway), and provide the projection of the extent yourself.
For example use the same as the projection of the map:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
proj = ccrs.PlateCarree(central_longitude=0)
fig, ax = plt.subplots(figsize=(11, 11), subplot_kw=dict(projection=proj), facecolor="w")
ax.gridlines(draw_labels=True, lw=1, color='gray', alpha=0.5, linestyle='--')
ax.coastlines()
ax.set_extent((-180, 60, 0, 60), crs=proj)
If you would change the last line, and explicitly provide a Geodetic projection:
ax.set_extent((-180, 60, 0, 60), crs=ccrs.Geodetic())
You'll again end up with:
Upvotes: 1