-2
Using holloviews and panel. How to create a function that takes as arguments an np.array (2d, an array) and a "value cut". Return the 2d array plotted as image? Being what the argument "value cut" should be interactive (a Floatslider).
I tried in a few ways, but every time I put 2d array as argument of the function of an ex error:
**** Attempt 1 ****
Returns error: Valueerror: The Truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
###################
import numpy as np
import holoviews as hv
from holoviews import opts
hv.extension('bokeh')
import panel as pn
pn.extension()
mat = np.random.rand(50,50) #2d array
slider = pn.widgets.FloatSlider(start=0.0, end=2.0, value=0.5, name='Cota de Corte: ') #cria ao widget
def plota_imagem (M, slider_corte):
corte = np.where(M <= slider_corte, M, np.nan)
img = hv.Image(corte)
return img
pn.interact(plota_imagem, M=mat, slider_corte=slider )
**** Attempt 2 ****
This way it works, but the 2d array is not as argument of the function and precise that it is.
##################
slider = pn.widgets.FloatSlider(start=0.0, end=1.0, value=0.5, name='Cota de Corte: ')
mat = np.random.rand(50,50) #2d array
def plota_imagem (slider_corte):
corte = np.where(mat<=slider_corte, mat, np.nan)
img = hv.Image(corte)
return img
pn.interact(plota_imagem,slider_corte=slider )
#####################
Is there any solution for Attempt 1 to work, that is, array 2d (mat) is also a function argument?