我正在使用各個模型網格框中的餅圖生成世界地圖。我用地圖製作地圖和海岸線。我使用inset_axes生成的餅圖。不幸的是,餅圖隱藏了海岸線,我想清楚地看到它們。由inset_axes隱藏的Cartopy海岸線使用Axes.pie
最低工作例如:
import cartopy.crs as ccrs
import numpy as np
import cartopy.feature as feature
import matplotlib.pyplot as plt
def plot_pie_inset(dataframe_pie,ilat_pie,ilon_pie,axis_main,width_local,alpha_local):
ax_sub= inset_axes(axis_main, width=width_local, height=width_local, loc=3, bbox_to_anchor=(ilat_pie, ilon_pie),bbox_transform=axis_main.figure.transFigure, borderpad=0.0)
wedges,texts= ax_sub.pie(dataframe_pie,colors=colors_dual)
for w in wedges:
w.set_linewidth(0.02)
w.set_alpha(alpha_local)
w.set_zorder(1)
plt.axis('equal')
colors_dual=['RosyBrown','LightBlue']
lat_list= np.arange(0.2,0.7,0.05)
fig= plt.figure()
ax_main= plt.subplot(1,1,1,projection=ccrs.PlateCarree())
ax_main.coastlines(zorder=3)
for ilat in np.arange(len(lat_list)):
plot_pie_inset([75,25],lat_list[ilat],0.72,ax_main,0.2,0.9)
plt.show()
我可以通過使餅圖通過減小α值部分透明看到海岸線。但是,這使得顏色有些淡化。我的目標是將海岸線作爲最頂層。
我曾嘗試使用'zorder'強制海岸線到頂層。但是,'zorder'不能傳遞給inset_axes,也不能傳遞給ax.pie,所以我已經使餅圖中的色塊變得透明。這會失敗,因爲ax_main.coastlines沒有自己的「zorder」。海岸線zorder似乎與ax_main的綁定。增加ax_main的zorder沒有任何好處。
非常歡迎任何建議。
非常感謝您的快速和有用的回覆。 – LeightonRegayre
我不清楚如何將背景補丁設置爲不可見,以允許海岸線可見。所使用的set_visible(False)是否適用於GeoAxes的背景和海岸線,或只是背景? 我想在可見和部分透明之間有一些細微的差別,這意味着看不見海岸線的線條。那是對的嗎? 再次感謝! – LeightonRegayre
背景是所有軸背後的白色矩形(因此也位於海岸線之後)。如果我們將插入物放在主軸的後面,這個白色矩形位於插入物的前面並隱藏它們。但是使背景不可見(即殺死白色矩形),可以看到主軸後面的所有內容都可以看到。 – ImportanceOfBeingErnest