Holoviews 曲线中的关键尺寸以在字典中查找值
Key dimensions in Holoviews curve to look up value in dictionary
我希望曲线的用户能够从滑块(斜率)调整曲线,但我希望从斜率到 return 的值是一组不同的值。
如果用户 select 1,曲线将使用值 0.5,如果用户 select 5,则曲线将使用值 0.8。
我尝试使用 lambda 表达式(如下面的脚本)和一些字典(因为我认为这是可行的方法),但我无法让它工作。
import numpy as np
import holoviews as hv
hv.extension('bokeh')
slope = [1, 5, 10]
def curve(slope):
x = np.linspace(1,10)
m = slope.apply(lambda x: 0.5 if slope == 1 else (0.8 if slope == 5 else (1)))
y = slope*0.5+x
err = x*m
return hv.Curve((x, y)) * hv.Spread((x,y,err))
curve_dict = {r:curve(r) for r in slope}
kdims = hv.Dimension(("slope", "slope"))
hv.HoloMap(curve_dict, kdims=kdims)
np.select() 根据条件更改值:
slopes = [1, 5, 10]
def curve(slope):
xs = np.linspace(1,10)
slope = np.select(
condlist=[slope==1, slope==5],
choicelist=[0.5, 0.8],
default=1,
)
ys = slope*0.5+xs
return hv.Curve((xs, ys))
curve_dict = {slope: curve(slope) for slope in slopes}
hv.HoloMap(curve_dict, kdims='slope')
我希望曲线的用户能够从滑块(斜率)调整曲线,但我希望从斜率到 return 的值是一组不同的值。
如果用户 select 1,曲线将使用值 0.5,如果用户 select 5,则曲线将使用值 0.8。
我尝试使用 lambda 表达式(如下面的脚本)和一些字典(因为我认为这是可行的方法),但我无法让它工作。
import numpy as np
import holoviews as hv
hv.extension('bokeh')
slope = [1, 5, 10]
def curve(slope):
x = np.linspace(1,10)
m = slope.apply(lambda x: 0.5 if slope == 1 else (0.8 if slope == 5 else (1)))
y = slope*0.5+x
err = x*m
return hv.Curve((x, y)) * hv.Spread((x,y,err))
curve_dict = {r:curve(r) for r in slope}
kdims = hv.Dimension(("slope", "slope"))
hv.HoloMap(curve_dict, kdims=kdims)
np.select() 根据条件更改值:
slopes = [1, 5, 10]
def curve(slope):
xs = np.linspace(1,10)
slope = np.select(
condlist=[slope==1, slope==5],
choicelist=[0.5, 0.8],
default=1,
)
ys = slope*0.5+xs
return hv.Curve((xs, ys))
curve_dict = {slope: curve(slope) for slope in slopes}
hv.HoloMap(curve_dict, kdims='slope')