本文介绍了如何使用背景虚化圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

维护人员的注意事项:此问题与过时的第一代Bokeh服务器有关.有关现代Bokeh服务器应用程序的详细信息,请参阅:

https://docs.bokeh.org/en/latest/docs/user_guide/server.html

过时:

OBSOLETE:

我目前正在使用这个散景通过服务器绘制散景,试图在一个圆圈中移动一个简单的项目.我一直在尝试学习的两个示例是 https://github.com/bokeh/bokeh/blob/master/examples/plotting/server/animated.py https://github.com/bokeh/bokeh/blob/master/examples/plotting/server/line_animate.py

I am currently working on this simple project using bokeh plotting through a server, attempting to move a circle in a circle. The two examples that I have been trying to learn from are https://github.com/bokeh/bokeh/blob/master/examples/plotting/server/animated.py and https://github.com/bokeh/bokeh/blob/master/examples/plotting/server/line_animate.py

由于他们的文档仍然非常有限,所以如果有人可以帮助,那就太好了.

As their documentation is still very limited, if anyone could help, that would be great.

import time 
import numpy as np
from bokeh.plotting import cursession, figure, show, output_server


output_server("circle_server")

pl = figure(y_range=(-2,2), x_range=(-2,2))

x=1
y=0

pl.circle(x, y, size=25, alpha=0.6, name="moving_circle") 
pl.annulus(x=0,y=0, inner_radius = 1, outer_radius = 1, line_alpha=0.6)


show(pl)

renderer = pl.select(dict(name="moving_circle"))
ds = renderer[0].data_source



while True:
    for rad in np.linspace(0,2*np.pi,100):
        #rad = deg*np.pi/180
        ds.data["x"] = np.cos(rad)
        ds.data["y"] = np.sin(rad)
        cursession().store_objects(ds)
        time.sleep(0.1)

推荐答案

维护者的注意事项:这个问题与过时的第一代Bokeh服务器有关.有关现代Bokeh服务器应用程序的详细信息,请参阅:

https://docs.bokeh.org/en/latest/docs/user_guide/server.html

过时:

OBSOLETE:

来自此处的文档:

http://docs .bokeh.org/en/latest/docs/reference/plotting.html#bokeh.plotting.Figure.circle

circle(图,* args,** kwargs)-参数:

circle(plot, *args, **kwargs) - Parameters:

  • x(str或list [float])–中心x坐标的值或字段名称

  • x (str or list[float]) – values or field names of center x coordinates

y(str或list [float])–中心y坐标的值或字段名称

y (str or list[float]) – values or field names of center y coordinates

因此,您需要在列表中传递值.要解决此问题,您只需在[x],[y],[np.cos(rad)]和[np.sin(rad)]中添加方括号即可.

So, you need to pass your values in a list. To fix it you can just add brackets in [x], [y], [np.cos(rad)] and [np.sin(rad)].

这是一个经过测试的有效解决方案:

Here's a tested working solution:

import time 
import numpy as np
from bokeh.plotting import cursession, figure, show, output_server


output_server("circle_server")

pl = figure(y_range=(-2,2), x_range=(-2,2))

x=1
y=0


pl.circle(x=[x], y=[y], size=25, alpha=0.6, name="circle") 
pl.annulus(x=0,y=0, inner_radius = 1, outer_radius = 1, line_alpha=0.6)


show(pl)

renderer = pl.select(dict(name="circle"))

ds = renderer[0].data_source

while True:
    for rad in np.linspace(0,2*np.pi,100):
        #rad = deg*np.pi/180
        ds.data["x"] = [np.cos(rad)]
        ds.data["y"] = [np.sin(rad)]
        cursession().store_objects(ds)
        time.sleep(0.5)

这篇关于如何使用背景虚化圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 09:12