简体   繁体   English

散景 - plot 外的图例

[英]Bokeh - legend outside the plot

There is plenty of issues like this one, but I couldn't find one with the approach I'm looking to solve it.有很多像这样的问题,但我找不到我想要解决的方法。

In bokeh we cannot move a legend outside the plot, we have to create one.在散景中,我们不能将图例移到 plot 之外,我们必须创建一个。 If we try nowadays to move the legend from inside to outside the legend dissapears.如果我们现在试图将传说从内部转移到外部,那么传说就会消失。 In the documentation (and in the solutions provided I have found in SO like 1 , 2 , and this solution does the copy but seems to use outdated fuctions), to plot an outside legend you need to create that legend from your data, not from the plot.文档中(以及在提供的解决方案中,我在 SO 中找到了12 ,并且解决方案进行了复制,但似乎使用了过时的功能),到 plot 一个外部图例,您需要根据您的数据创建该图例,而不是来自plot。

However, is it possible to access the existing legend inside the plot, copying it, and creating the outside legend.. with that copy?但是,是否可以访问 plot 中的现有图例,复制它,并使用该副本创建外部图例?

I'm looking for this approach because I developed a function that creates this plot, with two x-axis (date and category per date) and two y-axis (percentage and integers), so creating a legend that fits with every color, every line-style, every time the categories changes, for every plot.. it's kind of complicated.我正在寻找这种方法,因为我开发了一个 function 来创建这个 plot,有两个 x 轴(每个日期的日期和类别)和两个 y 轴(百分比和整数),所以创建一个适合每种颜色的图例,每种线条样式,每次类别更改时,对于每个 plot .. 这有点复杂。 So, as the inside legend is just perfect, I thought that just copying it to the outside new legend would be pretty straightforward, however I have not been able to do so.因此,由于内部传奇非常完美,我认为将其复制到外部新传奇将非常简单,但我无法这样做。

Any suggestions?有什么建议么?

Something like this?像这样的东西?

from bokeh.io import show
from bokeh.models import Legend
from bokeh.plotting import figure

p = figure(tools=[])
p.circle(x=[0, 1], y=[0, 1], size=10, legend_label='Circle')

legend = p.legend[0]
p.center = [item for item in p.center if not isinstance(item, Legend)]
p.add_layout(legend, 'right')

show(p)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM