更新散景图

时间:2016-03-08 01:33:25

标签: python plot bokeh

可以动态更新散景图而无需创建服务器或数据库吗?

这是文档中非常简单的情节:

from bokeh.plotting import figure, output_file, show
import time
x = [1, 2, 3, 4, 5]
y = [6, 7, 8, 7, 3]


output_file("multiple.html")

p = figure(plot_width=400, plot_height=400)

# add both a line and circles on the same plot
p.line(x, y, line_width=2)
p.circle(x, y, fill_color="white", size=8)

show(p)

是否可以通过更改列表x和y来更新绘图?

我试试这个:

from bokeh.plotting import figure, output_file, show
import time
x = [1, 2, 3, 4, 5]
y = [6, 7, 8, 7, 3]


output_file("multiple.html")

p = figure(plot_width=400, plot_height=400)

# add both a line and circles on the same plot
p.line(x, y, line_width=2)
p.circle(x, y, fill_color="white", size=8)

show(p)

for i in range (3):
    x.append(i)
    y.append(i*2)
    time.sleep(0.5)
    show(p)

但是,这只是为每个情节打开一个新的窗口。

我知道这种事情可以用matplotlib完成,但在浏览器中创建情节似乎很方便。

我想绘制一些我从arduino收到的数据。

编辑。

我也在尝试这个:

import time
from bokeh.objects import GlyphRenderer
renderer = [r for r in curplot().renderers if isinstance(r, GlyphRenderer)][0]
ds = renderer.data_source
while True:
    df = pd.io.json.read_json(url+json_call)
    ds.data["x"] = x+N*i
    ds.data["y"] = df.rssi
    ds._dirty = True
    session().store_obj(ds)
    time.sleep(1.5)
    i+=1

自: https://www.continuum.io/content/painless-streaming-plots-bokeh

独立代码不起作用

我正在尝试用数据框制作一个情节:

import time
from bokeh.models.renderers import GlyphRenderer
import pandas as pd
from bokeh.client import push_session
from bokeh.plotting import figure, curdoc


#renderer = [r for r in curplot().renderers if isinstance(r, GlyphRenderer)][0]
# open a session to keep our local document in sync with server
session = push_session(curdoc())


ds = pd.DataFrame({"x":[1,1,1],"y":[1,2,3]})
#ds = renderer.data_source
ds._dirty = True
session().store_obj(ds)

出现此错误:

TypeError: 'ClientSession' object is not callable

如果尝试:

session.store_obj(ds)

AttributeError: 'ClientSession' object has no attribute 'store_obj'

既不能使用:

session.store_objects(ds)

http://bokeh.pydata.org/en/0.10.0/docs/reference/plot_objects.html

0 个答案:

没有答案
相关问题