python - 图例在 Bokeh 图中的位置

标签 python visualization bokeh

有谁知道如何在图表的外部 Bokeh 中携带图例?我能做的唯一操作是在以下位置选择一个位置:

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

最佳答案

从 Bokeh 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

关于python - 图例在 Bokeh 图中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26254619/

相关文章:

python - 将纹理映射到 mayavi 网格

python - 如何使用 Python 的 Bokeh 更改刻度标签大小?

python - tqdm可以嵌入html吗?

python - 在 python 中解析 RDF 文件

python - 如果 pip 卸载失败会发生什么?

python - QDoubleSpinBox “backspace”键的编辑行为

r - 使用 stat_summary_hex 以离散色标显示最频繁的值

python - 总结 Pandas DataFrame 中的列值

visualization - Graphviz:左右子图,左右内部子图

hex - Python-sns.color_palette输出为Bokeh的十六进制数字