放大Cartopy地图并添加海洋功能会将整个图变成蓝色?

时间:2020-11-12 02:09:21

标签: python matplotlib geopandas cartopy

但是我有一个欧洲地块,由于某种原因,当我包含ax.add_feature(cartopy.feature.OCEAN)时,它将整个地块变成蓝色。我不确定如何解决此问题,我们将不胜感激!

这只有在我更改了扩大欧洲范围的程度时才发生。

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()

enter image description here

1 个答案:

答案 0 :(得分:0)

cartopy.feature.OCEAN是更复杂的NaturalEarthFeature函数的简单版本,使用起来更安全。这是几行代码,您可以用来替换麻烦的部分。

替换

ax.add_feature(cartopy.feature.OCEAN)

使用

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)

这使您可以将choice = 1或0设置为运行并检查图。

如果choice = 1,则输出为:

oceanx