[英]Zooming in on cartopy map and adding the ocean feature changes the entire plot to blue?
我有一個歐洲的 plot 但是,出於某種原因,當我包含ax.add_feature(cartopy.feature.OCEAN)
時,它會將整個 plot 變成藍色。 我不確定如何解決此問題,我們將不勝感激!
只有當我改變范圍以更多地放大歐洲時才會發生這種情況。
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
是更復雜的NaturalEarthFeature
function 的簡單版本,使用起來更安全。 這里有幾行代碼,你可以用它來替換麻煩的部分。
代替
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 並運行以檢查 plot。
如果 choice=1,則 output 將是:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.