Can not make the rasters transparent

Hi,
I tried to get rasterized transparent polygons.
I did this way. but it failed.

sp_df.hvplot(datashade=True,dynspread=True, width=1000,height=int(1000/ratio),cmap=['#ff0000'] , tiles=self.Altlık_Harita, min_alpha=20, alpha=50) 

How can I make the rasters transparent?
regards

1 Like

Hi Ahmet

If you want people to help you, try to post a minimal, reproducible example (MRE) instead of a single line.

A complete script that can be copied/pasted and immediately run, as-is, with no modifications. This is much more useful than snippets.

here is the code…

import param
import numpy as np
import pandas as pd
import geopandas as gpd
from geopandas import GeoSeries
from shapely.geometry import Polygon

import panel as pn
import  holoviews as hv
import colorcet as cc 
import datashader as ds
from holoviews.element.tiles import EsriImagery , OSM ,CartoLight  #, EsriImagery
from holoviews.operation.datashader import  dynspread, spread, rasterize
from bokeh.models import HoverTool, CustomJSHover
import hvplot.pandas
from holoviews import streams
from spatialpandas.io import to_parquet , read_parquet

from spatialpandas import GeoSeries, GeoDataFrame
pn.extension()
pn.config.throttled = True

gdf = gpd.read_parquet("fay.parquet") 
ratio= (5283334.352539557 - 2560348.2882452924)/(5296915.156925975-4074426.264922828)

gdf_hast = gpd.read_parquet("hast.parquet") 
gdf_hast = gdf_hast.set_index('fay_uzak')  #.tz_localize(None)   #reuired ??    

gdf_hast_Quaternary = gpd.read_parquet("hast_Quaternary.parquet") 
gdf_hast_Quaternary = gdf_hast_Quaternary.set_index('fay_uzak')  #.tz_localize(None)   #reuired ??    
print (" ,gdf_hast_Quaternary      ",gdf_hast_Quaternary.head())
data = [[2560348,4074426] ]
df0 = pd.DataFrame(data, columns=['x', 'y'])
print (df0.head())
class BaseClass (param.Parameterized):
     buf_range  = param.Integer(20, bounds=(10, 500),label='Tampon Büyüklüğü')
     Altlık_Harita = param.ObjectSelector(default="ESRI", objects=["ESRI", "OSM","EsriTerrain" ,"CartoLight"])

     @param.depends( 'buf_range','Altlık_Harita'  )
     def get_plot(self): # start function
          gdf['geometry'] = gdf.geometry.buffer(self.buf_range)   
          geo_series = GeoSeries(gdf.geometry)
          sp_df = GeoDataFrame(gdf)

          buff=sp_df.hvplot(datashade=True,dynspread=True, width=1000,height=int(1000/ratio),cmap=['#ff0000'] , tiles=self.Altlık_Harita,fill_alpha=50) 
          #buff = sp_df.hvplot(cmap=['#fee0d2','#ff0000'], rasterize=True ,width=1000,height=int(1000/ratio), xlim=(2560347 , 5283335),ylim=(4074425,  5296916),   tiles=self.Altlık_Harita,   min_alpha=20, alpha=30 ) 

          print ('buf_range  ',self.buf_range ) 

          filtered_hast = gdf_hast[
               gdf_hast.index <= self.buf_range]
          filtered_hast_Quaternary = gdf_hast_Quaternary[
               gdf_hast_Quaternary.index <= self.buf_range]
          critic=[]
          if len(filtered_hast.index) > 0:
             hast= filtered_hast.hvplot('x', 'y',kind='points', color='green',width=1000,height=int(1000/ratio),size=42, xlim=(2560347 , 5283335),ylim=( 4074425,  5296916  ),hover_cols=['ismi_ivm_jeo','fay_uzak']  ).opts(tools=['hover'])
             critic.append(hast)
          if len(filtered_hast_Quaternary.index) > 0:
             hast_Quaternary= filtered_hast_Quaternary.hvplot('x', 'y',kind='points', color='green',width=1000,height=int(1000/ratio),size=52, xlim=(2560347 , 5283335),ylim=( 4074425,  5296916  ),hover_cols=['ismi_ivm_jeo','fay_uzak'],line_color='yellow'  ).opts(tools=['hover'])
             critic.append(hast_Quaternary)
          
          geo0 = df0.hvplot('x', 'y', color='red', kind='points', width=1000,height=int(1000/ratio),size=1, xlim=(2560347 , 5283335),ylim=( 4074425,  5296916) ).opts(framewise=True)

          #return pn.Column( hv.Overlay([geo0]+[buff]+[hast]+[hast_Quaternary]).collate())
          return pn.Column( hv.Overlay([geo0]+[buff]+critic).collate())


base=BaseClass(name="")

app = pn.Column(
 pn.Param( base.param ,parameters=['buf_range','Altlık_Harita']),  base.get_plot  )
app.servable()

Hi Ahmet,

This is not a minimal reproducible example, as it is

  • It should be at most around 20-30 lines.
  • I can’t run it because you use files I don’t have access to. This does not mean you should upload the data file, but try to see if you can generate fake data which fits the purpose.

Try to read this excellent blog post on how to create an MRE: Craft Minimal Bug Reports

2 Likes