简体   繁体   中英

Bokeh streaming axes

When I'm using Bokeh Stream on Bokeh Server I start with an empty ColumnDataSource - however, this presents a problem as the figure is then generated with no axes labels and despite the data in the plot being updated the axes remain unchanged when it's plotted. It appears the solution to this is to have a fixed x_range and y_range - however, since it's constantly streaming I don't want it to be fixed...

I guess the solution is to update the ranges too but I'm not sure how to do this?

My code currently is as followed:

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

The graph looks like this, as can be seen the axes aren't updated automatically

在此处输入图片说明

If you don't create the axis + label beforehand you need to add some padding with the min_border properties of figure()

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM