2017-09-28 50 views
1

当我在散景服务器上使用散景流时,我从一个空的ColumnDataSource开始 - 但是,这会产生一个问题,因为随后会生成没有轴标签的图形,尽管绘图中的数据正在更新轴在绘制时保持不变。似乎解决方案是有一个固定的x_range和y_range - 但是,因为它不断流,我不希望它被固定...散景流轴

我想解决方案是更新范围,但我'米不知道如何做到这一点?

我的代码目前是如下:

source_ios = ColumnDataSource({'Date': [], 'Vol': []}) 
source_gp = ColumnDataSource({'Date': [], 'Vol': []}) 

ios = figure(toolbar_location=None, x_axis_type='datetime',plot_width=800, plot_height=250) 

ios.circle(x='Date',y='Vol', fill_color="pink",line_color=None, fill_alpha=0.05, size=20, source=source_ios) 

def update(): 
    MAU_ios = pd.read_csv('myapp/data/pplus_ios_data.csv') 
    MAU_ios['Date'] = pd.to_datetime(MAU_ios['Date']) 
    MAU_ios['Vol'] = MAU_ios.Vol.astype(int) 

    new_MAU_ios = {'Date':MAU_ios['Date'], 'Vol':MAU_ios['Vol']} 
    source_ios.stream(new_MAU_ios) 

curdoc().add_periodic_callback(update, 8000) 

curdoc().add_root(ios 

图表看起来像这样,可以看出轴不会自动更新

enter image description here

回答

1

如果不创建轴+标签事先您需要添加一些填充figure()min_border属性

from bokeh.io import curdoc 
from bokeh.plotting import figure 
from bokeh.models import ColumnDataSource 
from random import random 

source_ios = ColumnDataSource({'Date': [], 'Vol': []}) 

ios = figure(toolbar_location=None,plot_width=800, plot_height=250) 
ios.xaxis.axis_label = 'Date' 
ios.yaxis.axis_label = 'Vol' 
ios.min_border_left = 50 
ios.min_border_bottom = 50 

ios.circle(x='Date',y='Vol',color="pink", size=20, source=source_ios) 

i=0 
def update(): 
    global i 
    new_MAU_ios = {'Date':range(i,i+10),'Vol':[random() for j in range(10)]} 
    source_ios.stream(new_MAU_ios) 
    i+=10 

curdoc().add_periodic_callback(update, 8000) 

curdoc().add_root(ios)