This question already has an answer here:
Why isnt Bokeh generating extra y ranges here?
                                
                                    (1个答案)
                                
                        
                                2年前关闭。
            
                    
我的目标是在多个y轴(不同范围)上绘制实时数据。下面的代码适用于2 y轴,但是当我添加第3 y轴时,浏览器只是空白。早期的具有4 y轴的基本散景图可以正常工作,但该服务器版本无法正常工作。我不知道我在做什么错误,请指导我。

跟随的代码绘制了2个临时点,然后绘制了第3个永久点。使用ColumnDataSource中的'patch'和'stream'实现此目的。

from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.models import LinearAxis, Range1d
import numpy as np

def plotcharts(source,x,a,b,c):
    fig=figure(y_range=(0, 500))
    fig.circle(source=source, x=x,y=a,size=12,color='red')

    fig.extra_y_ranges = {"foo1": Range1d(start=0, end=50)}
    fig.circle(source=source,x=x, y=b, size=12, color="blue",
    y_range_name="foo1")
    fig.add_layout(LinearAxis(y_range_name="foo1"), 'left')

    # configure 3rd axis
    fig.extra_y_ranges = {"foo2": Range1d(start=0, end=25)}
    fig.circle(source=source, x=x, y=c, color="magenta",
    y_range_name="foo2")
    fig.add_layout(LinearAxis(y_range_name="foo2"), 'right')

    return fig

count=(-1)
dct=dict(x=[],a=[],b=[],c=[])
#Just a and b work fine but when 3rd axis c was added it doesnt !
source=ColumnDataSource(dct)
fig=plotcharts(source,'x','a','b','c') #c==3rd axis

def update_data():
    global count
    count=count+1
    y1 = np.random.randint(low=0, high=500)
    y2 = np.random.randint(low=0, high=50)
    y3 = np.random.randint(low=0, high=25) #y3==3rd axis

    if count%3==0:
        new_data = {
            'x': [count/3],
            'a': [y1],
            'b': [y2],
            'c': [y3]  #c==3rd axis
        }
        source.stream(new_data,rollover=20)

    else:
        l = len(df['a'])
        new_data = {
            'a': [(l - 1,y1)],
            'b': [(l - 1, y2)],
            'c': [(l - 1, y3)]  #c==3rd axis
        }
        source.patch(new_data)

curdoc().add_root(fig)
curdoc().add_periodic_callback(update_data,1000)

最佳答案

您的代码中包含以下两行:

fig.extra_y_ranges = {"foo1": Range1d(start=0, end=50)}
[...]
fig.extra_y_ranges = {"foo2": Range1d(start=0, end=25)}


Bokeh不会尝试在设置这些字段上做一些特殊的魔术,因此对于后者,您只需覆盖前者即可。相反,您应该只写一行:

fig.extra_y_ranges = {"foo1": Range1d(start=0, end=50), "foo2": Range1d(start=0, end=25)}

关于python - 具有3个y轴的Bokeh Server不会绘制,但是会绘制2个y轴。为什么? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48441861/

10-14 00:58