散景-如何将y值添加到水平跨度的y轴?

一月

如何在y轴上显示和突出显示水平跨度的值?

import bokeh as bk
import bokeh.plotting as bkplot
#bkplot.output_notebook() # to show inline

x = np.arange(3)
y = x**2

source = bk.models.ColumnDataSource(dict(x=x, y=y))

p = bkplot.figure(plot_width=500, plot_height=300)

glyph = bk.models.Line(x="x", y="y", line_width=6)
p.add_glyph(source, glyph)

top_span = bk.models.Span(location=3.5, dimension='width', line_color='green', line_width=2)
bottom_span = bk.models.Span(location=1.5, dimension='width', line_color='red', line_width=2)
p.renderers.extend([top_span, bottom_span])

bkplot.show(p)

结果:

在此处输入图片说明

所需结果:

在此处输入图片说明

hyles_lineata

在Bokeh的github中已经讨论了这个问题:https : //github.com/bokeh/bokeh/issues/7309

因此,尚未实现在轴区域与图区域中的跨度上具有标签。

但是,如果在打印区域中可以使用标签,则可以使用标签。这是我对标签所做的事情:

top_span = bk.models.Span(location=3.5, dimension='width', line_color='green', line_width=2)
top_span_label = bk.models.Label(text_color='green', text=str(top_span.location), x=0, y=top_span.location)
bottom_span = bk.models.Span(location=1.5, dimension='width', line_color='red', line_width=2)
bottom_span_label = bk.models.Label(text_color=bottom_span.line_color, text=str(bottom_span.location), x=0, y=bottom_span.location)
p.renderers.extend([top_span, top_span_label, bottom_span, bottom_span_label])

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章