2016-12-06 65 views
0

儘管底圖圖片背後沒有任何東西,但我想調整它的透明度以使其不那麼明顯 - 基本上讓它變得無趣。我一直試圖將alpha=0.5插入到我的代碼中的幾個位置,但它沒有任何作用或不能運行。如何調整底圖圖像(matplotlib)的透明度?

我已經嘗試將alpha=0.5放入plt.figure(),Basemap()和map.arcgisimage()中。是否有另一種方法可以將ESRI圖像顯示作爲褪色或不透明的版本?

geomap = plt.figure(figsize=(10,9)) 
ax1 = plt.axes([0.075, 0.01, 0.875, 0.975]) 
map = Basemap(llcrnrlon=self.LLcrnrlon ,llcrnrlat=self.LLcrnrlat,urcrnrlon=self.URcrnrlon, 
urcrnrlat=self.URcrnrlat, epsg=4269, projection='tmerc',lat_0 = self.center[0], 
lon_0 = self.center[1]) 
map.arcgisimage(service='ESRI_Imagery_World_2D', xpixels = 2500,dpi=150, 
    verbose= True, alpha=0.9) 
parallels = np.arange(round(self.LLcrnrlat,1),round(self.URcrnrlat,1),0.2) 
map.drawparallels(parallels,labels=[True, False, False, False],linewidth=0) 
meridians = np.arange(round(self.LLcrnrlon,1),round(self.URcrnrlon,1),0.2) 
map.drawmeridians(meridians,labels=[False, False, False, True],linewidth=0) 
+0

我不知道底圖IDEO,但如果一切都失敗了,你可以放置一個半透明白色['matplotlib.patches.Rectangle'(http://matplotlib.org/api/patches_api.html#matplotlib。 patch.Rectangle)橫跨整個軸區域以達到相同的效果。 – ImportanceOfBeingErnest

回答

0

您必須在圖像上使用.set_alpha()。

# etc. 
img = map.arcgisimage(service='ESRI_Imagery_World_2D', xpixels=2500, dpi=150, verbose= True) 
img.set_alpha(0.2) 
# etc. 
plt.show()