下面是一个简单的bokeh‘快速入门’示例:
from bokeh.plotting import Figure
output_file("lines.html")
xs = [1, 2, 3, 4, 5]
ys = [6, 7, 2, 4, 5]
p = Figure()
p.line(xs, ys, legend="Temp.", line_width=2)
show(p)这是可行的。现在,如果我子类Figure,脚本仍然可以正常运行并生成html页面,但是浏览器将只显示一个空白页面:
from bokeh.plotting import Figure
class TestFigure(Figure):
def __init__(self):
super().__init__()
output_file("lines.html")
xs = [1, 2, 3, 4, 5]
ys = [6, 7, 2, 4, 5]
p = TestFigure()
p.line(xs, ys, legend="Temp.", line_width=2)
show(p)这是故意的吗?
发布于 2019-02-08 00:37:21
Bokeh类是高度工具化的,以便促进Python和JavaScript之间的自动序列化和同步。特别是,每个Bokeh类实际上都有两部分,一部分是Python语言,另一部分是JavaScript语言。如果在Python端创建子类,则必须提供相应的JavaScript实现。因此,仅仅在Python端进行子类化是不够的,您需要使用create an entire custom extension。除非您确实利用了自定义扩展可以提供的功能,否则很可能不值得这么做。
TLDR: Bokeh类通常不应该被子类化,除非是为了进行自定义(JavaScript)扩展。
https://stackoverflow.com/questions/54577800
复制相似问题