绘图中的各种字形可以通过图例属性识别,默认情况下在绘图区域的右上角位置显示为标签。该图例可以通过以下属性进行自定义 -
legend.label_text_font
- 将默认标签字体更改为指定字体名称legend.label_text_font_size
- 字体大小(以点为单位)legend.location
- 在指定位置设置标签。legend.title
- 为图例标签设置标题legend.orientation
- 设置为水平(默认)或垂直legend.clicking_policy
- 指定点击图例时应该发生什么? hide:隐藏图例对应的字形 mute:静音图例对应的字形
图例自定义的示例代码如下 -
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)
运行结果: