matplotlib 控制图形大小并单独声明轴

2cmtqfgy  于 2022-12-23  发布在  其他
关注(0)|答案(1)|浏览(116)

目标-具有自定义大小的图形,轴具有Cartopy投影。

fig=plt.subplots(figsize=(20,10))
#Supress the ticklabels on the x axis
plt.tick_params(labelbottom=False)
plt.tick_params(labelleft=False) #Otherwise I get a tick_label from 0 to 1 on both axes.

ax=plt.axes(projection=ccrs.PlateCarree()) #This is the projection I want to use.
ax.set_global()
ax.coastlines()
ax.gridlines()
ax.set_xticks(np.arange(-180,180,30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-90,90,30), crs=ccrs.PlateCarree())
ax.set_xticklabels(np.arange(-180,180,30), fontsize=10);
ax.set_yticklabels(np.arange(-90,90,30), fontsize=10);

for i in range(len(geofieldcol)):
    ax.scatter(geofieldcol[i][1],geofieldcol[i][0],s=0.1,transform=ccrs.PlateCarree())
    ax.text(geofieldcol[i][1][0]+1.0,geofieldcol[i][0][0]-8,"Orbit "+str(i+1),rotation=80,
    size=15,fontweight="bold", transform=ccrs.PlateCarree())
    
plt.show()

此程序在x1c 0d1x图上运行良好
但是我们可以看到,在左右边界,fig和axis之间存在一些不匹配,如何在保持fig较大的同时,使figax正确对齐?
我不能尝试fig,ax=fig.subplots(figsize=(20,10)),因为我需要为投影单独声明ax
plt.tight_layout()在这种情况下没有帮助。

mbzjlibv

mbzjlibv1#

在使用plt.tight_layout()时尝试设置pad=0。从docs
参数:
焊盘浮动,默认值:1.08
图形边缘和子图边缘之间的填充,作为字体大小的一部分。
但这会让你的蜱虫看不见,如果你需要它们,根据你的需要调整值。

相关问题