2014-10-08 46 views
18

有沒有人知道如何在散景以外的圖例的圖表?我唯一能做的操作是選擇中的位置:用傳說中散景的位置

top_right, top_left, bottom_left or bottom_right 

legend()[0].orientation = "bottom_left" 

,當我嘗試不同的人,我得到錯誤信息:

ValueError: invalid value for orientation: 'outside'; allowed values are top_right, top_left, bottom_left or bottom_right 
+0

一個問題密切相關的是:如何保持原有軸的長徑比? – 2017-08-25 10:04:33

回答

11

由於散景0.12.4可以將傳說放置在中心地塊區域之外。下面是一個簡單的例子from the user's guide

import numpy as np 
from bokeh.models import Legend 
from bokeh.plotting import figure, show, output_file 

x = np.linspace(0, 4*np.pi, 100) 
y = np.sin(x) 

output_file("legend_labels.html") 

p = figure(toolbar_location="above") 

r0 = p.circle(x, y) 
r1 = p.line(x, y) 

r2 = p.line(x, 2*y, line_dash=[4, 4], line_color="orange", line_width=2) 

r3 = p.square(x, 3*y, fill_color=None, line_color="green") 
r4 = p.line(x, 3*y, line_color="green") 

legend = Legend(items=[ 
    ("sin(x)", [r0, r1]), 
    ("2*sin(x)", [r2]), 
    ("3*sin(x)", [r3, r4]) 
], location=(0, -30)) 

p.add_layout(legend, 'right') 

show(p) 

要調整位置,在location=(dx, dy)改變dxdy

enter image description here

+0

使用圖表API時我該怎麼做? – kynan 2016-07-26 16:52:05

+0

這將需要移動佈局位置,目前這不是微不足道的。我建議將這樣的問題帶到郵件列表中,因爲它可能需要一些實驗和來回討論才能找出答案。 – bigreddot 2016-09-13 12:52:06

+0

我曾[提交過該功能的問題](https://github.com/bokeh/bokeh/issues/4941)。 – kynan 2016-09-28 16:50:25