title: How to make pixels with values less than 0.2 transparent so the base map in the background can be visible in Python?
body: <p>I am interpolating point data to generate dynamic flood inundation maps in a for loop. This produces a flood map in each iteration where the pixel values show the probability of water presence. However, I'm unable to make the dry pixels (values &lt; 0.2) transparent so the base map can be seen when added. </p>
  
  <p>Initially I created a geodataframe of predicted probabilities. Then generated raster files using rasterio library using the condition ( &lt;0.2 = np.nan) to set dry pixels. My code is:</p>
  
  <pre><code>    geom = [Point(xy) for xy in zip(df.X, df.Y)]
      crs = {'init': 'epsg:27700'}
      gdf = geopandas.GeoDataFrame(df, crs=crs, geometry=geom)
  
      ###Rasterization
  
      #Set up filenames
  
      rst_fn = 'dem_9m_study_area.asc' #template raster
  
      out_fn = 'Raster.tif'
  
      rst = rasterio.open(rst_fn)
  
      #copy and update the metadata from the input raster for the output
  
      meta = rst.meta.copy()
      meta.update(compress='lzw')
  
      with rasterio.open(out_fn, 'w', **meta) as out:
          out_arr = out.read(1)
          shapes = ((geom,value) for geom, value in zip(gdf.geometry, gdf.Prob))
          burned = features.rasterize(shapes=shapes, fill=0, out=out_arr, transform=out.transform)
          burned[burned &lt; 0.2] = np.nan
          out.write_band(1, burned)
  </code></pre>
  
  <p>Now i would like to import the saved raster and plot it over a background raster which is also in the same coordinate (EPSG:27700), and also show the color bar.</p>
  
  <p>I tried this:</p>
  
  <pre><code>    plt.figure(num=None, figsize=(10, 8), dpi=80, facecolor='w', edgecolor='k')
      plt.imshow(burned, cmap='Blues')
      plt.colorbar()
      plt.xlabel('X')
      plt.ylabel('Y')
      plt.title('Flood Extent: T=%i h'%op)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/eZYA4.png" rel="nofollow noreferrer">Extent with values &lt;0.2 set to nan</a></p>
  
  <p>this works fine without the background though the x and y coordinates are not showing correctly. But does not work if I add this to the above code:</p>
  
  <pre><code>bmap = rasterio.open("background_upton.tif") #import basemap
      src = bmap.read(1)
      plt.imshow(src, cmap = 'pink')
  </code></pre>
  
  <p>I also tried the method described in "Adding a background map to plots": <a href="https://geopandas.readthedocs.io/en/latest/gallery/plotting_basemap_background.html" rel="nofollow noreferrer">https://geopandas.readthedocs.io/en/latest/gallery/plotting_basemap_background.html</a></p>
  
  <p>But this does not seem to solve the problem. It would be great if I can get some suggestions how to solve the issue.
  <a href="https://i.stack.imgur.com/AXOuZ.png" rel="nofollow noreferrer">I want to overlay the extent map using this background image</a></p>