Bokeh - 自定義圖例



圖形中的各種 Glyph 可以透過圖例屬性來識別,預設情況下圖例顯示為圖形區域右上角的標籤。可以透過以下屬性自定義此圖例:

1 legend.label_text_font 將預設標籤字型更改為指定的字型名稱。
2 legend.label_text_font_size 以磅為單位的字型大小。
3 legend.location 在指定位置設定標籤。
4 legend.title 設定圖例標籤的標題。
5 legend.orientation 設定為水平(預設)或垂直。
6 legend.clicking_policy 指定單擊圖例時應發生什麼:hide:隱藏對應於圖例的 Glyph;mute:靜音對應於圖例的 Glyph。

示例

圖例自定義的示例程式碼如下:

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)

輸出

Customising legends
廣告