我有一段使用matplotlib绘制一系列线并应用颜色映射的代码。以下是代码摘录和结果:
cm = plt.cm.get_cmap('jet')
step = 15
xi = np.linspace(data[data.columns[0]].min(), data[data.columns[0]].max(), 2)
colors_l = np.linspace(0.1, 1, len(state_means[::step]))
for i, beta in enumerate(state_means[::step]):
plt.plot(xi, beta[0] * xi + beta[1], alpha=.2, lw=1, c=cm(colors_l[i]))
这里相关的代码部分是
c=cm(colors_l[i])
这段代码涉及plt.plot()函数,可以使用参数(此处为i)来索引颜色映射。
但是,如果我想使用bokeh的ColorMapper和line() glyph实现类似的效果,就会遇到错误。相关的代码行和输出如下:
call_color_mapper = LinearColorMapper(palette="Viridis256", low=min(call_strike_vals), high=max(call_strike_vals))
call_lines=dict()
call_chain_plot = figure(y_axis_label='Call OI', x_axis_label='Dates', x_axis_type = 'datetime')
for strike in call_strikes:
call_lines[strike] = call_chain_plot.line('TIMESTAMP', strike, line_color=call_color_mapper(int(strike[2:])), source=callSource)
TypeError: 'LinearColorMapper' object is not callable
有没有一种方法可以使用颜色映射器在bokeh中对一组线状glyph进行着色?