簡體   English   中英

控制圖形大小並單獨聲明軸

[英]Control size of figure and declare axes separately

目標 - 擁有一個自定義大小的圖形,其軸具有 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()

這個程序在這個情節上運行良好地軌

但是,我們可以看到在左右邊界中,fig 和 axes 之間存在一些不匹配。 如何在保持大fig尺寸的同時使figax正確對齊?

我不能嘗試fig,ax=fig.subplots(figsize=(20,10))因為我需要為投影單獨聲明ax

plt.tight_layout()在這種情況下沒有幫助。

使用plt.tight_layout()時嘗試設置pad=0 文檔

參數:

padfloat,默認值:1.08
圖邊緣和子圖邊緣之間的填充,作為字體大小的一部分。

但這會讓你看不見蜱蟲。 如果您需要它們,請根據您的需要調整值。

如果您需要分別更改頂部、右側、底部和左側的填充,請嘗試設置pad=0並將rect=[0, 0, 1, 1]的定義更改為更小的值(例如[.05, .05, 1, 1] )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM