在Jupyter笔记本中运行内联Bokeh应用程序在与localhost:8888不同的URL上运行,可以通过以下步骤实现:
pip install bokeh
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource
output_notebook()
# 创建数据源
source = ColumnDataSource(data=dict(x=[1, 2, 3, 4, 5], y=[2, 4, 6, 8, 10]))
# 创建绘图对象
p = figure(plot_width=400, plot_height=400)
# 添加散点图
p.circle('x', 'y', source=source, size=10)
# 显示图形
show(p)
server
模块。首先,导入必要的库:from bokeh.server.server import Server
from tornado.ioloop import IOLoop
def modify_doc(doc):
# 创建数据源
source = ColumnDataSource(data=dict(x=[1, 2, 3, 4, 5], y=[2, 4, 6, 8, 10]))
# 创建绘图对象
p = figure(plot_width=400, plot_height=400)
# 添加散点图
p.circle('x', 'y', source=source, size=10)
# 将图形添加到文档
doc.add_root(p)
# 创建服务器
server = Server({'/': modify_doc}, io_loop=IOLoop.current(), allow_websocket_origin=['*'])
# 启动服务器
server.start()
http://localhost:8889/
请注意,上述代码中的URL和端口号可以根据需要进行更改。
这是一个基本的示例,演示了如何在Jupyter笔记本中运行内联Bokeh应用程序并在与localhost:8888不同的URL上运行。根据具体的需求和场景,可以进一步定制和扩展Bokeh应用程序。
领取专属 10元无门槛券
手把手带您无忧上云