简体   繁体   中英

Zooming in on cartopy map and adding the ocean feature changes the entire plot to blue?

I have a plot of Europe however, for some reason, when I include the ax.add_feature(cartopy.feature.OCEAN) it turns the entire plot blue. I am not sure how to fix this, any help is appreciated!

This only happened when I changed the extent to zoom in more on Europe.

plt.figure(figsize=(9, 9))
ax = plt.axes(projection=cartopy.crs.TransverseMercator(32))
ax.add_feature(cartopy.feature.BORDERS, linestyle='-', alpha=1)
ax.coastlines(resolution='110m')
ax.gridlines()
ax.set_extent((-7.5, 50, 34, 55), cartopy.crs.PlateCarree())
ax.add_feature(cartopy.feature.OCEAN)
plt.show()

在此处输入图像描述

cartopy.feature.OCEAN is a simple version of more complex NaturalEarthFeature function that is safer to use. Here is a few lines of code that you can use to replace the troublesome part.

Replace

ax.add_feature(cartopy.feature.OCEAN)

with

choice = 1
if choice==1:
    # this solves the problem
    ocean110 = cartopy.feature.NaturalEarthFeature('physical', 'ocean', \
        scale='110m', edgecolor='none', facecolor=cartopy.feature.COLORS['water'])
    ax.add_feature(ocean110)
else:
    # this (sometimes) causes the ocean spill all over
    ax.add_feature(cartopy.feature.OCEAN)

This allows you to set choice=1 or 0 and run to check the plot.

If choice=1, the output will be:

大洋

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM