I am trying to make a plot of Europe with Cartopy and I want to fill in the ocean a different colour to the land. I believe I should be able to sue the line of code:
ax.add_feature(ctp.feature.OCEAN, facecolor=(0.5,0.5,0.5))
in order to do this, however when I do the map shown below is produced. This is clearly not what I would like to achieve. Is anyone able to help me and see what is wrong with my code?
I have put the code in below for it to be reproduced locally.
import cartopy as ctp
import cartopy.crs as ccrs
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 10))
ax = plt.axes(projection=ccrs.EuroPP())
ax.add_feature(ctp.feature.BORDERS, linestyle='-', alpha=1)
ax.coastlines(resolution='10m')
ax.add_feature(ctp.feature.OCEAN,facecolor=(0.5,0.5,0.5))
ax.coastlines()
ax.gridlines()
plt.show()
The projection ccrs.EuroPP()
source is a subclass of UTM, which is a subclass of transversemercator
. The complexities of subclassing may be the cause of the bad result. You can try my code that uses straight forward projection TransverseMercator(central_longitude=10)
which should be nearly equivalent with EuroPP
. The values in ax.set_extent()
can be adjusted to get the areas you want on the map.
plt.figure(figsize=(10, 10))
# Start- relevant code
pp_euro = ccrs.TransverseMercator(central_longitude=10)
ax = plt.axes(projection=pp_euro)
ax.set_extent([-1800000, 2050000, 4000000, 8000000], crs=pp_euro)
# End- relevant code
ax.add_feature(ctp.feature.BORDERS, linestyle='-', alpha=1)
ax.coastlines(resolution='10m')
ax.add_feature(ctp.feature.OCEAN,facecolor=(0.5,0.5,0.5))
ax.coastlines()
ax.gridlines(draw_labels=True)
plt.show()