简体   繁体   中英

Bokeh Heatmap Legend

I am trying to create a legend for a heatmap in bokeh. I decided that creating a separate plot that will stand to the right of my heatmap was the best way to go about it because there are a lot of custom calculations. I have the below code but for some reason only the first 2 colors are showing. I can't seem to find what is wrong. Also, how can I display custom labels instead of y-axis values in this chart? For example, how would I display 'Label_1' in place of '1' on the y-axis?

Thanks

from bokeh.plotting import ColumnDataSource, figure, output_file, show
import numpy as np
from collections import OrderedDict

color = []
val = []

color.append('rgb(255,255,255)')
val.append('1')
color.append('rgb(204,229,255)')    
val.append('2')
color.append('rgb(153,204,255)')     
val.append('3')
color.append('rgb(102,178,255)')     
val.append('4')
color.append('rgb(51,153,255)')   
val.append('5')
color.append('rgb(0,128,255)') 
val.append('6')
color.append('rgb(0,102,204)')                
val.append('7')
color.append('rgb(0,25,51)')
val.append('8')

source = ColumnDataSource(
    data=OrderedDict(color=color,val=val))

p = figure(title=None,x_range=[0,1], y_range=val)

p.rect([0,1], 'val', 1, 1, source=source, color='color')

p.plot_width = 100
p.plot_height = 500

p.grid.grid_line_color = None
p.axis.axis_line_color = None
p.axis.major_tick_line_color = None
p.axis.major_label_text_font_size = "9pt"
p.axis.major_label_standoff = 0
p.xaxis.major_label_orientation = np.pi/2

show(p) 

output_file('heatmap_legend.html')

This was an issue with the 'height' of the bars. You need to assign a height of 1 for each element in the array that is passed to Bokeh.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM