散景中的无限水平线 [英] Infinite horizontal line in Bokeh
问题描述
有没有办法用Bokeh画一条无限的水平线? 无论用户缩放到多远,该线的端点都永远不可见.
Is there a way to plot an infinite horizontal line with Bokeh? The endpoints of the line should never become visible, no matter how far out the user is zooming.
这是我到目前为止尝试过的.它只是打印一个空的画布:
This is what I've tried so far. It just prints an empty canvas:
import bokeh.plotting as bk
import numpy as np
p = bk.figure()
p.line([-np.inf,np.inf], [0,0], legend="y(x) = 0")
bk.show(p)
一种方法是将端点设置为极高/极低,并且图形的x_range和y_range相对于它们极小.
One way would be to set the endpoints extremely high/low and the figure's x_range and y_range very small in relation to them.
import bokeh.plotting as bk
import numpy as np
p = bk.figure(x_range=[-10,10])
p.line([-np.iinfo(np.int64).max, np.iinfo(np.int64).max], [0,0], legend="y(x) = 0")
bk.show(p)
但是,我希望有人能有一个更优雅的解决方案.
However, I am hoping that somebody has a more elegant solution.
删除过时的解决方案
推荐答案
您正在寻找跨度":
跨度(线型注释)具有一个维度(宽度或高度),并延伸到绘图区域的边缘.
Spans (line-type annotations) have a single dimension (width or height) and extend to the edge of the plot area.
请看看 http://docs.bokeh.org/en/latest/docs /user_guide/annotations.html#spans
因此,代码将如下所示:
So, the code will look like:
import numpy as np
import bokeh.plotting as bk
from bokeh.models import Span
p = bk.figure()
# Vertical line
vline = Span(location=0, dimension='height', line_color='red', line_width=3)
# Horizontal line
hline = Span(location=0, dimension='width', line_color='green', line_width=3)
p.renderers.extend([vline, hline])
bk.show(p)
使用此解决方案,用户可以随意平移和缩放.行的结尾将永远不会显示.
With this solution users are allowed to pan and zoom at will. The end of the lines will never show up.
这篇关于散景中的无限水平线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!