如何在Bokeh图像p中更改颜色映射器

2024-10-01 11:32:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Bokeh图像图,我想以交互方式更改,例如:

color_mapper = LinearColorMapper(palette="Viridis256", low=tmp.min(), high=tmp.max())
p = figure(plot_width=tmp.shape[0], plot_height=tmp.shape[1], 
           x_range=(0, tmp.shape[0]), y_range=(0, tmp.shape[1]))
img = p.image(image=[tmp], x=[0], y=[0], dw=[tmp.shape[0]], 
              dh=[tmp.shape[1]], color_mapper=color_mapper)

我可以使用以下方法更新彩色地图中的范围:

^{pr2}$

但是,我希望能够交互式地更改为不同类型的颜色映射,例如从LinearColorMapper到{}。上面只允许我访问LinearColorMapper对象,而不是替换它。有没有一种方法可以在不需要再次调用image的情况下以交互方式执行此操作?在


Tags: 方法图像imageplotbokehrangemintmp
1条回答
网友
1楼 · 发布于 2024-10-01 11:32:15

找到它,它在image实例的glyph对象中。你可以用另一个ColorMapper来代替它,例如:

img.glyph.color_mapper = LogColorMapper(palette="Viridis256",
                                        low=new_data.min(),
                                        high=new_data.max())
push_notebook()

相关问题 更多 >