Created
May 4, 2020 20:05
-
-
Save philippemiron/cebccfcb199a94ebba1e8bce597ce6a6 to your computer and use it in GitHub Desktop.
Problem with cartopy NaturalEarthFeature bathymetry feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import cartopy.feature as cfeature | |
import cartopy.crs as ccrs | |
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter | |
fig = plt.figure(figsize=(10, 4), dpi=300) | |
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree(), aspect='equal') | |
ax.set_extent([-80, 10, 35, 80], crs=ccrs.PlateCarree()) | |
# ticks | |
ax.set_xticks(np.arange(-80, 20, 20), crs=ccrs.PlateCarree()) | |
ax.set_yticks(np.arange(40, 100, 20), crs=ccrs.PlateCarree()) | |
ax.xaxis.set_major_formatter(LongitudeFormatter()) | |
ax.yaxis.set_major_formatter(LatitudeFormatter()) | |
# add land and coastline and 1000m bathymetry line | |
ax.add_feature(cfeature.LAND, facecolor='grey', zorder=1) | |
ax.add_feature(cfeature.COASTLINE, linewidth=0.25, zorder=1) | |
bathym = cfeature.NaturalEarthFeature(name='bathymetry_J_1000', scale='10m', category='physical') | |
ax.add_feature(bathym, facecolor='none', edgecolor='black') |
Thanks, that looks promising. Is there a way to plot contour() and not contourf() using this?
I haven't tried those yet, but I guess everything should come along with matplotlib interface, with transform
specified by Cartopy crs, for instance:
ax1.scatter(lon, lat, s=50, ec="black", fc="orange", transform=ccrs.Geodetic())
I got help on Github.
Here is an updated code.
import numpy as np
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
import cartopy.crs as ccrs
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
from shapely.ops import cascaded_union
fig = plt.figure(figsize=(10, 4), dpi=300)
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree(), aspect='equal')
ax.set_extent([-100, 10, 0, 90], crs=ccrs.PlateCarree())
# ticks
ax.set_xticks(np.arange(-90, 30, 30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(40, 100, 20), crs=ccrs.PlateCarree())
ax.xaxis.set_major_formatter(LongitudeFormatter())
ax.yaxis.set_major_formatter(LatitudeFormatter())
# add land and coastline and 1000m bathymetry line
ax.add_feature(cfeature.LAND, facecolor='grey', zorder=1)
ax.add_feature(cfeature.COASTLINE, linewidth=0.25, zorder=1)
bathym = cfeature.NaturalEarthFeature(name='bathymetry_J_1000', scale='10m', category='physical')
bathym = cascaded_union(list(bathym.geometries()))
ax.add_geometries(bathym, facecolor='none', edgecolor='black', linestyle='dashed', linewidth=1, crs=ccrs.PlateCarree())
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had the same problem using that bathymetry data. I solved it by switching to use GEBCO (WMS address is here). The resolution is much better!
Example: