Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从AjaxDataSource提供的Bokeh绘图中删除旧数据(刷新缓冲区)?_Python_Bokeh - Fatal编程技术网

Python 从AjaxDataSource提供的Bokeh绘图中删除旧数据(刷新缓冲区)?

Python 从AjaxDataSource提供的Bokeh绘图中删除旧数据(刷新缓冲区)?,python,bokeh,Python,Bokeh,使用AjaxDataSource时,是否可以删除以追加模式传输的旧数据 以下是我正在运行的代码: import numpy as np from flask import Flask, jsonify, make_response, request from bokeh.plotting import figure, show from bokeh.models import AjaxDataSource, CustomJS # Bokeh related code adapter = C

使用AjaxDataSource时,是否可以删除以追加模式传输的旧数据

以下是我正在运行的代码:

import numpy as np
from flask import Flask, jsonify, make_response, request

from bokeh.plotting import figure, show
from bokeh.models import AjaxDataSource, CustomJS

# Bokeh related code

adapter = CustomJS(code="""
    const result = {x: [], y: []}
    const pts = cb_data.response.points
    for (i=0; i<pts.length; i++) {
        result.x.push(pts[i][0])
        result.y.push(pts[i][1])
    }
    return result
""")

source = AjaxDataSource(data_url='http://localhost:5050/data',
                        polling_interval=200, adapter=adapter, mode='append', max_size=20)

p = figure(plot_height=300, plot_width=800, background_fill_color="lightgrey",
           title="Streaming Noisy sin(x) via Ajax")
p.circle('x', 'y', source=source)

p.x_range.follow = "end"
p.x_range.follow_interval = 10

# Flask related code

app = Flask(__name__)

def crossdomain(f):
    def wrapped_function(*args, **kwargs):
        resp = make_response(f(*args, **kwargs))
        h = resp.headers
        h['Access-Control-Allow-Origin'] = '*'
        h['Access-Control-Allow-Methods'] = "GET, OPTIONS, POST"
        h['Access-Control-Max-Age'] = str(21600)
        requested_headers = request.headers.get('Access-Control-Request-Headers')
        if requested_headers:
            h['Access-Control-Allow-Headers'] = requested_headers
        return resp
    return wrapped_function

x = list(np.arange(0, 6, 0.1))
y = list(np.sin(x) + np.random.random(len(x)))

@app.route('/data', methods=['GET', 'OPTIONS', 'POST'])
@crossdomain
def data():
    x.append(x[-1]+0.1)
    y.append(np.sin(x[-1])+np.random.random())
    return jsonify(points=list(zip(x,y)))

# show and run

show(p)
app.run(port=5050)
将numpy导入为np
从烧瓶导入烧瓶,jsonify,作出响应,请求
从bokeh.plotting导入图形,显示
从bokeh.models导入AjaxDataSource、CustomJS
#博克相关代码
adapter=CustomJS(代码=“”)
常量结果={x:[],y:[]}
const pts=cb_data.response.points

对于(i=0;iDid)您可以尝试将源代码设置为:
source.data={'x:[],'y':[]}
,然后将源代码设置为
source.change.emit()
?@Tony如果我这样做,我会得到“AttributeError:'dict'对象没有属性'change',如果我删除source.data={}行,那么我会得到“AttributeError:'AjaxDataSource'对象没有属性'change'”不知道如何继续。
source
应该是您的
AjaxDataSource
并且它肯定不是
dict
,所以我不明白。但是您也可以尝试
data={'x:[],'y':[]}
然后
source.data=data
相反,它确实可以用空值替换AjaxDataSource。但是它不能替换缓冲区中已经存在的内容。我尝试了更改函数,结果得到:
AttributeError:'AjaxDataSource'对象没有属性“更改”
@tony,更改不是ColumnDataSource的函数,它是是AjaxDataSource继承的。