Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在matplotlib中使用cartopy投影时无法删除轴脊椎_Python_Matplotlib_Cartopy - Fatal编程技术网

Python 在matplotlib中使用cartopy投影时无法删除轴脊椎

Python 在matplotlib中使用cartopy投影时无法删除轴脊椎,python,matplotlib,cartopy,Python,Matplotlib,Cartopy,我一直在python 2.7中使用cartopy和matplotlib来可视化地图上的一些数据。但是,当我尝试使用以下代码片段删除轴脊椎(顶部和右侧)时: ax1.spines['top'].set_visible(False) ax1.spines['right'].set_visible(False) 这是行不通的。设置脊椎厚度也不起作用: ax1.spines['left'].set_linewidth(3) ax1.spines['bottom'].set_linewidth(

我一直在python 2.7中使用cartopy和matplotlib来可视化地图上的一些数据。但是,当我尝试使用以下代码片段删除轴脊椎(顶部和右侧)时:

ax1.spines['top'].set_visible(False)
ax1.spines['right'].set_visible(False)  
这是行不通的。设置脊椎厚度也不起作用:

 ax1.spines['left'].set_linewidth(3)
 ax1.spines['bottom'].set_linewidth(3)  
当我使用cartopy投影时,上面的代码行对绘图没有影响。但是如果我使用常规matplotlib轴,它们工作正常。
我也尝试过提到的rcParams方法,但没有效果。
我在下面包含我的代码的精简版本:

lons=np.arange(10, 50, .5)
lats=np.arange(7, 44, .5)

xticks=np.arange(math.ceil(lons.min()),
        math.floor(lons.max())+4, 4)
yticks=np.arange(math.ceil(lats.min()),
        math.floor(lats.max())+4, 4)

fig=plt.figure()    
ax1=fig.add_subplot(111,
        projection=ccrs.PlateCarree())

ax1.set_extent([lons[0], lons[-1],
        lats[0], lats[-1]],
        crs=ccrs.PlateCarree())
ax1.coastlines()

ax1.set_xticks(xticks)
ax1.set_yticks(yticks)

ax1.spines['top'].set_visible(False)
ax1.spines['right'].set_visible(False)

ax1.spines['left'].set_linewidth(3)
ax1.spines['bottom'].set_linewidth(3)  
plt.show()
我使用miniconda管理软件包,使用的相关模块版本如下:

Python - 2.7.16
matplotlib - 2.3.3
cartopy - 0.17.0
那么,在使用cartopy投影时,如何移除这些脊椎

更新

我深入挖掘,发现了这些:


这些都与我的问题有关。从这些帖子的信息中,我找到了解决问题的方法:
首先,必须使用以下代码关闭轴或脊椎

ax1.outline_patch.set_visible(False)
然后,您可以使用axis.spines['']方法打开单个脊椎,如下所示

ax1.spines['left'].set_visible(True)  
ax1.spines['bottom'].set_visible(True)  
然后设置脊椎线条宽度:

ax1.spines['left'].set_linewidth(3)  
ax1.spines['bottom'].set_linewidth(3)  
结果如下:


有没有更合适的方法来做我想做的事?

我使用了与你相同的方法,即首先,关闭所有四个轴,然后显示其中两个。@HanZhengzu我不确定Cartopy是否提供了更直接的方法来做这件事,但我真的希望他们有。我花了几周的时间在这上面,但没有用,因为我有一个很大的图,如果你放大每个子图,刺会比颜色条的宽度厚,这看起来不太好。