图例在散景图中的位置 [英] Position of the legend in a Bokeh plot
本文介绍了图例在散景图中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何在图的外部背景虚化中携带图例吗?我唯一能做的就是在以下位置中选择一个职位:
Does anyone know how to carry the legend in bokeh outside of the graph? The only manipulation I could do was to choose a position among:
top_right, top_left, bottom_left or bottom_right
使用:
legend()[0].orientation = "bottom_left"
当我尝试其他方法时,出现错误消息:
and when I try different ones I get the error message:
ValueError: invalid value for orientation: 'outside'; allowed values are top_right, top_left, bottom_left or bottom_right
推荐答案
从散景0.12.4
开始,可以将图例放置在中央绘图区域之外.这是一个简短示例,来自用户的指南:
As of Bokeh 0.12.4
it is possible to position legends outside the central plot area. Here is a short example 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)
中更改dx
和dy
.
To adjust the position, change dx
and dy
in location=(dx, dy)
.
这篇关于图例在散景图中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文