自版本 2.0.0 以来散景图损坏
bokeh graph broken since version 2.0.0
从 bokeh 版本 2.0.0 开始,我不再从下面的代码中获取输出。昨天代码还好,现在不行了。预期输出是 geograph ,它仅显示与过滤日期对应的数据。我正在使用 jupyter 笔记本并尝试 ipython。我已经 运行 一步一步地尝试了代码并且一切 运行 都很好,直到 "doc.add_root(layout)".
python版本:3.6.8,散景版本:2.0.0
编辑:
实际上我没有任何 output.Jupyter 笔记本只打印 BokehJS 2.0.0 加载如下图。
Edit2 我删除了虚拟环境并重新安装了它。新的散景版本是 2.0.1,我现在得到这个输出。
数据作为字典(样本):
data = {'date': {66: '2015-08-13',
317: '2015-07-16',
61: '2015-07-09',
71: '2015-09-17',
294: '2016-01-29'},
'location': {66: 'fason',
317: 'yenidogan',
61: 'fason',
71: 'fason',
294: 'sultanbeyli'},
'qty': {66: 68016.0, 317: 1309952.0, 61: 55134.0, 71: 55699.0, 294: 641157.0},
'wh': {66: 2, 317: 3, 61: 2, 71: 2, 294: 2},
'x_axis': {66: 3253339.8929858636,
317: 3255353.4952555867,
61: 3253339.8929858636,
71: 3253339.8929858636,
294: 3255618.7696021474},
'y_axis': {66: 5012258.806203845,
317: 5015160.9407821335,
61: 5012258.806203845,
71: 5012258.806203845,
294: 5008555.491935941},
'density': {66: 34008.0,
317: 436650.66666666674,
61: 27567.0,
71: 27849.5,
294: 320578.5},
'color': {66: 'green', 317: 'red', 61: 'green', 71: 'green', 294: 'orange'},
'c_size': {66: 750, 317: 750, 61: 750, 71: 750, 294: 750}}
数据link(完整数据):link
代码:
import pandas as pd
pd.set_option('display.float_format', lambda x: '%d' % x)
import numpy as np
import datetime
from datetime import datetime
import math
from math import pi
#import warnings
#warnings.filterwarnings("ignore")
import bokeh
from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
from bokeh.core.properties import value
from bokeh.io import output_file, output_notebook, push_notebook
from bokeh.layouts import column,row
from bokeh.models import HoverTool
from bokeh.models import ColumnDataSource
from bokeh.models import NumeralTickFormatter
from bokeh.models import DatetimeTickFormatter
from bokeh.models import Column
from bokeh.models import Legend
from bokeh.models import Select
from bokeh.palettes import Colorblind
from bokeh.plotting import figure, show
from bokeh.tile_providers import CARTODBPOSITRON, get_provider
# df = pd.read_csv('data.csv')
df = pd.DataFrame(data, columns = ['date', 'location', 'qty', 'wh', 'x_axis', 'y_axis', 'density', 'color', 'c_size'])
def modify_doc(doc):
def make_dataset(date):
data = df[df['date'] == date]
data = data[data['qty'] != 0]
return ColumnDataSource(data)
def update():
date_to_plot = date_selection.value
new_src = make_dataset(date_to_plot)
src.data.update(new_src.data)
def graph(src):
tile_provider = get_provider(CARTODBPOSITRON)
# range bounds supplied in web mercator coordinates
z = figure(x_range=(3254079.2550728847,3274493.100585638), y_range=(4983881.858145405,5018160.940782133),
x_axis_type="mercator", y_axis_type="mercator")
z.title.text = 'Warehouse Change'
z.add_tile(tile_provider)
z.circle(x='x_axis', y ='y_axis',source=src, radius='c_size',color='color', alpha=0.5)
tooltips1 = [
('Location','@location'),
('Number of Warehouses','@wh{,}'),
('Number of Items','@qty{,}')
]
z.add_tools(HoverTool(tooltips=tooltips1))
return z
date_list = ['2015-04-30','2015-05-07','2015-05-14','2015-05-21','2015-05-28','2015-06-04',
'2015-06-11','2015-06-18','2015-06-25','2015-07-02','2015-07-09','2015-07-16',
'2015-07-23','2015-07-30','2015-08-06','2015-08-13','2015-08-20','2015-08-27',
'2015-09-03','2015-09-10','2015-09-17','2015-09-24','2015-10-01','2015-10-08',
'2015-10-15','2015-10-22','2015-10-29','2015-11-05','2015-11-12','2015-11-19',
'2015-11-26','2015-12-03','2015-12-10','2015-12-17','2015-12-24','2015-12-31',
'2016-01-07','2016-01-15','2016-01-22','2016-01-29','2016-02-05','2016-02-12',
'2016-02-19','2016-02-26','2016-03-04','2016-03-11','2016-03-18','2016-03-25',
'2016-04-01','2016-04-08','2016-04-15']
date_selection = Select(title="Date:", value='2015-04-30', options=date_list)
date_selection.on_change('value', lambda attr, old, new: update())
controls = Column(date_selection)
initial_list = date_selection.value
src = make_dataset(initial_list)
fig = graph(src)
layout = Column(controls, fig)
doc.add_root(layout)
output_notebook()
handler = FunctionHandler(modify_doc)
app = Application(handler)
show(app)
您的笔记本不在默认端口 8888 上 运行,因此您在调用 show 时明确需要设置 notebook_url
:
# The error message stated the URL to use here
show(app, notebook_url="http://localhost:8891")
每当笔记本 URL 不是默认设置时,您都需要设置此项。
如果 Bokeh 可以自动检测和调整,那就太好了,但是 Jupyter 团队(多年来)一直拒绝提供支持 publicAPI for Python 知道当前笔记本地址的代码,所以不幸的是这是不可能的。
仅供参考,这已经存在很长时间了,所以您现在恰好 运行 在非默认端口上,并且新的 Bokeh 2.x 在同时.
从 bokeh 版本 2.0.0 开始,我不再从下面的代码中获取输出。昨天代码还好,现在不行了。预期输出是 geograph ,它仅显示与过滤日期对应的数据。我正在使用 jupyter 笔记本并尝试 ipython。我已经 运行 一步一步地尝试了代码并且一切 运行 都很好,直到 "doc.add_root(layout)".
python版本:3.6.8,散景版本:2.0.0
编辑:
实际上我没有任何 output.Jupyter 笔记本只打印 BokehJS 2.0.0 加载如下图。
Edit2 我删除了虚拟环境并重新安装了它。新的散景版本是 2.0.1,我现在得到这个输出。
数据作为字典(样本):
data = {'date': {66: '2015-08-13',
317: '2015-07-16',
61: '2015-07-09',
71: '2015-09-17',
294: '2016-01-29'},
'location': {66: 'fason',
317: 'yenidogan',
61: 'fason',
71: 'fason',
294: 'sultanbeyli'},
'qty': {66: 68016.0, 317: 1309952.0, 61: 55134.0, 71: 55699.0, 294: 641157.0},
'wh': {66: 2, 317: 3, 61: 2, 71: 2, 294: 2},
'x_axis': {66: 3253339.8929858636,
317: 3255353.4952555867,
61: 3253339.8929858636,
71: 3253339.8929858636,
294: 3255618.7696021474},
'y_axis': {66: 5012258.806203845,
317: 5015160.9407821335,
61: 5012258.806203845,
71: 5012258.806203845,
294: 5008555.491935941},
'density': {66: 34008.0,
317: 436650.66666666674,
61: 27567.0,
71: 27849.5,
294: 320578.5},
'color': {66: 'green', 317: 'red', 61: 'green', 71: 'green', 294: 'orange'},
'c_size': {66: 750, 317: 750, 61: 750, 71: 750, 294: 750}}
数据link(完整数据):link
代码:
import pandas as pd
pd.set_option('display.float_format', lambda x: '%d' % x)
import numpy as np
import datetime
from datetime import datetime
import math
from math import pi
#import warnings
#warnings.filterwarnings("ignore")
import bokeh
from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
from bokeh.core.properties import value
from bokeh.io import output_file, output_notebook, push_notebook
from bokeh.layouts import column,row
from bokeh.models import HoverTool
from bokeh.models import ColumnDataSource
from bokeh.models import NumeralTickFormatter
from bokeh.models import DatetimeTickFormatter
from bokeh.models import Column
from bokeh.models import Legend
from bokeh.models import Select
from bokeh.palettes import Colorblind
from bokeh.plotting import figure, show
from bokeh.tile_providers import CARTODBPOSITRON, get_provider
# df = pd.read_csv('data.csv')
df = pd.DataFrame(data, columns = ['date', 'location', 'qty', 'wh', 'x_axis', 'y_axis', 'density', 'color', 'c_size'])
def modify_doc(doc):
def make_dataset(date):
data = df[df['date'] == date]
data = data[data['qty'] != 0]
return ColumnDataSource(data)
def update():
date_to_plot = date_selection.value
new_src = make_dataset(date_to_plot)
src.data.update(new_src.data)
def graph(src):
tile_provider = get_provider(CARTODBPOSITRON)
# range bounds supplied in web mercator coordinates
z = figure(x_range=(3254079.2550728847,3274493.100585638), y_range=(4983881.858145405,5018160.940782133),
x_axis_type="mercator", y_axis_type="mercator")
z.title.text = 'Warehouse Change'
z.add_tile(tile_provider)
z.circle(x='x_axis', y ='y_axis',source=src, radius='c_size',color='color', alpha=0.5)
tooltips1 = [
('Location','@location'),
('Number of Warehouses','@wh{,}'),
('Number of Items','@qty{,}')
]
z.add_tools(HoverTool(tooltips=tooltips1))
return z
date_list = ['2015-04-30','2015-05-07','2015-05-14','2015-05-21','2015-05-28','2015-06-04',
'2015-06-11','2015-06-18','2015-06-25','2015-07-02','2015-07-09','2015-07-16',
'2015-07-23','2015-07-30','2015-08-06','2015-08-13','2015-08-20','2015-08-27',
'2015-09-03','2015-09-10','2015-09-17','2015-09-24','2015-10-01','2015-10-08',
'2015-10-15','2015-10-22','2015-10-29','2015-11-05','2015-11-12','2015-11-19',
'2015-11-26','2015-12-03','2015-12-10','2015-12-17','2015-12-24','2015-12-31',
'2016-01-07','2016-01-15','2016-01-22','2016-01-29','2016-02-05','2016-02-12',
'2016-02-19','2016-02-26','2016-03-04','2016-03-11','2016-03-18','2016-03-25',
'2016-04-01','2016-04-08','2016-04-15']
date_selection = Select(title="Date:", value='2015-04-30', options=date_list)
date_selection.on_change('value', lambda attr, old, new: update())
controls = Column(date_selection)
initial_list = date_selection.value
src = make_dataset(initial_list)
fig = graph(src)
layout = Column(controls, fig)
doc.add_root(layout)
output_notebook()
handler = FunctionHandler(modify_doc)
app = Application(handler)
show(app)
您的笔记本不在默认端口 8888 上 运行,因此您在调用 show 时明确需要设置 notebook_url
:
# The error message stated the URL to use here
show(app, notebook_url="http://localhost:8891")
每当笔记本 URL 不是默认设置时,您都需要设置此项。
如果 Bokeh 可以自动检测和调整,那就太好了,但是 Jupyter 团队(多年来)一直拒绝提供支持 publicAPI for Python 知道当前笔记本地址的代码,所以不幸的是这是不可能的。
仅供参考,这已经存在很长时间了,所以您现在恰好 运行 在非默认端口上,并且新的 Bokeh 2.x 在同时.