我正在尝试使用Bokeh服务器创建动态图
当我向其传递两个x和y轴数据数组(然后bokeh服务--show cursedfile.py)时,此代码有效:
p = figure(plot_width=400, plot_height=400, x_range = x_range, y_range = y_range)
r1 = p.line([], [], color="firebrick", line_width=2)
ds1 = r1.data_source
i = 0
@linear()
def update(step):
global i
ds1.data['x'].append(xdata[i])
ds1.data['y'].append(ydata[i])
ds1.trigger('data', ds1.data, ds1.data)
i = i + 1
curdoc().add_root(p)
curdoc().add_periodic_callback(update, 100)
一旦我尝试将其放入类中的函数中,然后调用它,就会显示该框架,但数据不会呈现:
class Graph(object):
def __init__(self, dataset, **kwargs):
self.dataset = dataset
self.height =kwargs.get('height')
self.width = kwargs.get('width')
self.lats = dataset["lat"].tolist()
self.lons = dataset["lon"].tolist()
self.lat_range = None
self.lon_range = None
self.p = None
self.r1 = None
self.ds1 = None
self.i = 0
@linear()
def update(self, step):
global i
self.ds1.data['x'].append(self.lons[i])
self.ds1.data['y'].append(self.lats[i])
self.ds1.trigger('data', self.ds1.data, self.ds1.data)
i = i + 1
def animategraph(self):
self.p = figure(plot_width=self.width, plot_height=self.height, x_range = self.lon_range, y_range = self.lat_range)
self.r1 = self.p.line([], [], color="firebrick", line_width=2)
self.ds1 = self.r1.data_source
curdoc().add_root(self.p)
curdoc().add_periodic_callback(self.update, 1000)
这是我每1000毫秒在服务器上收到的错误
AttributeError: '_asyncio.Future' object has no attribute 'exc_info'
2018-10-20 15:01:11,595 Error thrown from periodic callback:
2018-10-20 15:01:11,595 Exception in callback functools.partial(<function wrap.<locals>.null_wrapper at 0x0BB65420>, <Future finished exception=TypeError('wrapper() takes 0 positional arguments but 1 was given')>)
Traceback (most recent call last):
File "c:\users\xxx\appdata\local\programs\python\python37-32\lib\site-packages\tornado\ioloop.py", line 758, in _run_callback
ret = callback()
File "c:\users\xxx\appdata\local\programs\python\python37-32\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "c:\users\xxx\appdata\local\programs\python\python37-32\lib\site-packages\bokeh\util\tornado.py", line 96, in on_done
log.error("".join(format_exception(*future.exc_info())))
AttributeError: '_asyncio.Future' object has no attribute 'exc_info'
我的直觉是与“更新对变量的访问或“动画图”对“更新”的访问有关,因此我对变量初始化不满意。我也尝试过将“更新”作为定义放在“动画”中,但并不高兴。
非常感谢收到任何建议或指示!