gpt4 book ai didi

python - 自版本 2.0.0 以来 Bokeh 图损坏

转载 作者:行者123 更新时间:2023-12-04 04:13:26 28 4
gpt4 key购买 nike

从 bokeh 版本 2.0.0 开始,我不再从下面的代码中获得输出。昨天代码还好,现在不行了。预期输出是 geograph ,它仅显示与过滤日期对应的数据。我正在使用 jupyter notebook 并在 ipython 上试过。我已尝试逐步运行代码,一切运行良好,直到“doc.add_root(layout)”。

python版本:3.6.8,bokeh版本:2.0.0

编辑:实际上我没有任何输出。Jupyter notebook 仅打印 BokehJS 2.0.0 loaded 如下图所示。 Jupyter Output

Edit2 我删除了虚拟环境并重新安装了它。新的 Bokeh 版本是 2.0.1,我现在得到这个输出。

enter image description here

作为字典的数据(样本):

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

代码:

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 团队一直(多年来)坚决拒绝为 Python 代码提供受支持的公共(public) API 以了解当前的笔记本地址,所以不幸的是这是不可能的。

仅供引用,这已经存在很长时间了,所以您现在恰好在非默认端口上运行,并且同时在新的 Bokeh 2.x 上运行纯属巧合。

关于python - 自版本 2.0.0 以来 Bokeh 图损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61241986/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com