Bokeh – Customising legends

Bokeh - Customising legends

Bokeh – Customising legends. Various glyphs in a plot can be identified by legend property appear as a label by default at the top-right position of the plot area. This legend can be customized by following attributes −

1legend.label_text_fontchange default label font to the specified font name
2legend.label_text_font_sizefont size in points
3legend.locationset the label at the specified location.
4legend. titleset title for legend label
5legend. orientationset to horizontal (default) or vertical
6legend.clicking_policyspecify what should happen when the legend is clicked hide: hides the glyph corresponding to legend mute: mutes the glyph corresponding to legendtd>

Example of Bokeh customising legends

Example code for legend customization is as follows −

from bokeh.plotting import figure, output_file, show
import math
x2 = list(range(1,11))
y4 = [math.pow(i,2) for i in x2]
y2 = [math.log10(pow(10,i)) for i in x2]
fig = figure(y_axis_type = 'log')
fig.circle(x2, y2,size = 5, color = 'blue', legend = 'blue circle')
fig.line(x2,y4, line_width = 2, line_color = 'red', legend = 'red line')
fig.legend.location = 'top_left'
fig.legend.title = 'Legend Title'
fig.legend.title_text_font = 'Arial'
fig.legend.title_text_font_size = '20pt'
show(fig)

Output

Bokeh - Customising legends

Next Topic – Click Here

Leave a Reply