我试着go 掉剧情的顶部和右侧的脊椎,最初try 了

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

这给了我这个数字,也就是说,它显然不起作用

enter image description here

然后我试着移除框架并添加我想要的两根脊椎

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

这也不太管用-我成功地移除了框架,但无法将左侧和底部的脊椎重新放回

enter image description here

我确实看到了这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'

当然,一定有办法实现这一点?有人知道怎么做吗?我使用的是python3.10.

推荐答案

我认为现代的outline_patchspines['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()

enter image description here

Python相关问答推荐

三个给定的坐标可以是矩形的点吗

使用numpy提取数据块

将特定列信息移动到当前行下的新行

如何使用html从excel中提取条件格式规则列表?

从dict的列中分钟

为什么以这种方式调用pd.ExcelWriter会创建无效的文件格式或扩展名?

对所有子图应用相同的轴格式

如何在给定的条件下使numpy数组的计算速度最快?

将tdqm与cx.Oracle查询集成

Asyncio:如何从子进程中读取stdout?

Django admin Csrf令牌未设置

在matplotlib中删除子图之间的间隙_mosaic

判断Python操作:如何从字面上得到所有decorator ?

裁剪数字.nd数组引发-ValueError:无法将空图像写入JPEG

在第一次调用时使用不同行为的re. sub的最佳方式

如何从数据框列中提取特定部分并将该值填充到其他列中?

FileNotFoundError:[WinError 2]系统找不到指定的文件:在os.listdir中查找扩展名

将Pandas DataFrame中的列名的长文本打断/换行为_STRING输出?

有什么方法可以在不对多索引DataFrame的列进行排序的情况下避免词法排序警告吗?

如何在微调Whisper模型时更改数据集?