Can I plot a colorbar for a bokeh heatmap?

前端 未结 6 1537
再見小時候
再見小時候 2020-12-30 06:26

Does bokeh have a simple way to plot the colorbar for a heatmap?

In this example it would be a strip illustrating how colors correspond to values.

6条回答
  •  暖寄归人
    2020-12-30 07:10

    Since other answers here seem very complicated, here an easily understandable piece of code that generates a colorbar on a bokeh heatmap.

    import numpy as np
    from bokeh.plotting import figure, show
    from bokeh.models import LinearColorMapper, BasicTicker, ColorBar
    
    
    data = np.random.rand(10,10)
    
    color_mapper = LinearColorMapper(palette="Viridis256", low=0, high=1)
    
    plot = figure(x_range=(0,1), y_range=(0,1))
    plot.image(image=[data], color_mapper=color_mapper,
               dh=[1.0], dw=[1.0], x=[0], y=[0])
    
    color_bar = ColorBar(color_mapper=color_mapper, ticker= BasicTicker(),
                         location=(0,0))
    
    plot.add_layout(color_bar, 'right')
    
    show(plot)
    

提交回复
热议问题