I have data which is -100o - 30o lon and 0o - 80o lat.
I would like to use a projection to only show this region.
In my head I would like to show a plot like this:
However, when I try the AlbersEqualArea projection as follows:
plt.figure(figsize=(5.12985642927, 3))
ax = plt.axes(projection=ccrs.AlbersEqualArea(central_longitude=-35, central_latitude=40, standard_parallels=(0, 80)))
ax.set_extent([lon180[0], lon180[-1], lat[0], lat[-1]], ccrs.Geodetic())
I get a map showing:
What is the best way to show the area that I have data for?
Cheers, Ray
If you want to have a non-rectangular boundary you'll have to define it yourself. Something like the following may work for you:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import matplotlib.path as mpath
proj = ccrs.AlbersEqualArea(central_longitude=-35,
central_latitude=40,
standard_parallels=(0, 80))
ax = plt.axes(projection=proj)
ax.set_extent([-100, 30, 0, 80], crs=ccrs.PlateCarree())
ax.coastlines()
# Make a boundary path in PlateCarree projection, I choose to start in
# the bottom left and go round anticlockwise, creating a boundary point
# every 1 degree so that the result is smooth:
vertices = [(lon, 0) for lon in range(-100, 31, 1)] + \
[(lon, 80) for lon in range(30, -101, -1)]
boundary = mpath.Path(vertices)
ax.set_boundary(boundary, transform=ccrs.PlateCarree())
plt.show()
I think maybe you would need to add AlbersEqualArea as a transform on the plot, maybe more like this.
来源:https://stackoverflow.com/questions/43463643/cartopy-albersequalarea-limit-region-using-lon-and-lat