如何调整底图图像的透明度(matplotlib)?

时间:2016-12-06 18:18:46

标签: matplotlib transparency matplotlib-basemap

虽然底图图片背后没有任何内容,但我想调整其透明度以使其不那么明显 - 基本上是为了使它变钝。我一直在尝试将alpha=0.5插入到我的代码中的几个位置,但它要么没有效果要么不能运行。

我尝试将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)

1 个答案:

答案 0 :(得分: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()