Bokeh 简明教程

Bokeh - Customising legends

图中的各种字形可以通过在默认情况下显示为图区右上角标签的图例属性来识别。可以通过以下属性自定义此图例:

1

legend.label_text_font

将默认标签字体更改为指定的字体名称

2

legend.label_text_font_size

font size in points

3

legend.location

将标签设置在指定的位置。

4

legend.title

为图例标签设置标题

5

legend.orientation

设置为水平(默认)或垂直

6

legend.clicking_policy

Example

图例自定义的示例代码如下:

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

customising legends