散景如何在通过multi_line方法创建的图形上添加图例? [英] Bokeh how to add legend to figure created by multi_line method?

查看:111
本文介绍了散景如何在通过multi_line方法创建的图形上添加图例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在图上添加图例,其中包含由multi_line方法创建的两行. 示例:

I'm trying to add legend to a figure, which contains two lines created by multi_line method. Example:

p = figure(plot_width=300, plot_height=300)
p.multi_line(xs=[[4, 2, 5], [1, 3, 4]], ys=[[6, 5, 2], [6, 5, 7]], color=['blue','yellow'], legend="first")

在这种情况下,图例仅用于第一行.将图例定义为列表时,将出现错误:

In this case the legend is only for the first line. When the legend is defined as a list there is an error:

p.multi_line(xs=[[4, 2, 5], [1, 3, 4]], ys=[[6, 5, 2], [6, 5, 7]], color=['blue','yellow'], legend=["first","second"])

是否可以在许多行中添加图例?

Is it possible to add legend to many lines?

推荐答案

维护者注意:

Maintainer Note: PR #8218 which will be merged for Bokeh 1.0, allows legends to be created directly for multi line and patches, without any looping or using separate line calls.

multi_line用于概念上单一的事物,碰巧具有多个子组件.想想德克萨斯州,这是合乎逻辑的事情,但是它有几个不同的(且不相交)多边形.您可以使用Patches绘制德克萨斯州"的所有多边形,但总体上只需要一个图例.图例标记逻辑事物.如果要将几行标记为逻辑上不同的事物,则必须使用p.line(..., legend_label="...")

multi_line is intended for conceptually single things, that happen to have multiple sub-components. Think of the state of Texas, it is one logical thing, but it has several distinct (and disjoint) polygons. You might use Patches to draw all the polys for "Texas" but you'd only want one legend overall. Legends label logical things. If you want to label several lines as logically distinct things, you will have to draw them all separately with p.line(..., legend_label="...")

这篇关于散景如何在通过multi_line方法创建的图形上添加图例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆