SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def get_color_for_val(val, vmin, vmax, pl_colorscale):
  2.     if vmin >= vmax:
  3.         raise ValueError('vmin should be < vmax')
  4.        
  5.     plotly_scale, plotly_colors = list(map(float, np.array(pl_colorscale)[:,0])), np.array(pl_colorscale)[:,1]  
  6.     colors_01=np.array(list(map(literal_eval,[color[3:] for color in plotly_colors] )))/255.
  7.    
  8.     v= (val - vmin) / float((vmax - vmin))
  9.  
  10.     idx = 0
  11.    
  12.     while(v > plotly_scale[idx+1]):
  13.         idx+=1
  14.     left_scale_val = plotly_scale[idx]
  15.     right_scale_val = plotly_scale[idx+ 1]
  16.     vv = (v - left_scale_val) / (right_scale_val - left_scale_val)
  17.    
  18.     val_color01 = colors_01[idx]+vv*(colors_01[idx + 1]-colors_01[idx])
  19.     val_color_0255 = list(map(np.uint8, 255*val_color01+0.5))
  20.     return 'rgb'+str(tuple(val_color_0255))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top