删除 GeoAxesSubplot 中的顶部和右侧脊柱

问题描述 投票:0回答:1

我正在尝试删除情节的顶部和右侧脊柱,并最初尝试过

# Create a figure and axis with PlateCarree projection
fig, ax = plt.subplots(figsize=(11, 6), 
                       subplot_kw={'projection': ccrs.PlateCarree()})

ax.coastlines()

# Reintroduce spines
ax.spines['top'].set_visible(True)
ax.spines['right'].set_visible(True)

ax.set_xticks(range(-180, 181, 30), crs=ccrs.PlateCarree())
ax.set_yticks(range(-90, 91, 30), crs=ccrs.PlateCarree())

# Show the plot
plt.show()

这给了我这个数字,即它显然不起作用

然后我尝试移除框架并添加我想要的两个书脊

# Create a figure and axis with PlateCarree projection
fig, ax = plt.subplots(figsize=(11, 6), 
                       subplot_kw={'projection': ccrs.PlateCarree(), 
                                   'frameon': False})

ax.coastlines()

# Reintroduce spines
ax.spines['left'].set_visible(True)
ax.spines['bottom'].set_visible(True)

ax.set_xticks(range(-180, 181, 30), crs=ccrs.PlateCarree())
ax.set_yticks(range(-90, 91, 30), crs=ccrs.PlateCarree())

# Show the plot
plt.show()

这也不太有效 - 我成功移除了框架,但无法重新引入左侧和底部脊柱背部

我确实看到了这个post但是当我尝试将其应用到我的代码中时

# Create a figure and axis with PlateCarree projection
fig, ax = plt.subplots(figsize=(11, 6), 
                       subplot_kw={'projection': ccrs.PlateCarree()})

ax.coastlines()

# Reintroduce spines
ax.outline_patch.set_visible(False)
ax.spines['left'].set_visible(True)  
ax.spines['bottom'].set_visible(True)  

ax.set_xticks(range(-180, 181, 30), crs=ccrs.PlateCarree())
ax.set_yticks(range(-90, 91, 30), crs=ccrs.PlateCarree())

# Show the plot
plt.show()

我收到错误

AttributeError: 'GeoAxes' object has no attribute 'outline_patch'

肯定有办法实现这一点吗?有谁知道如何做到这一点?我正在使用 python 3.10。

python matplotlib cartopy map-projections
1个回答
0
投票

我认为

outline_patch
的现代等价物是
spines['geo']
:

# Create a figure and axis with PlateCarree projection
fig, ax = plt.subplots(figsize=(11, 6), 
                       subplot_kw={'projection': ccrs.PlateCarree()})

ax.coastlines()

ax.spines['geo'].set_visible(False)
ax.spines['left'].set_visible(True)
ax.spines['bottom'].set_visible(True)

ax.set_xticks(range(-180, 181, 30), crs=ccrs.PlateCarree())
ax.set_yticks(range(-90, 91, 30), crs=ccrs.PlateCarree())

# Show the plot
plt.show()

© www.soinside.com 2019 - 2024. All rights reserved.