python - 散景图像的动态更新
问题描述
我正在使用 jupyter/notebooks 或 jupyter/lab。
我想以动态方式更改散景显示的图像内容 - 在按钮单击、组合框更改或背景线程更改时。尽管更改 1D 图形的内容很容易,如示例笔记本中所示,但我仍坚持更改散景生成的 2D 图像的内容。我将不胜感激任何帮助使其工作。
这是最简单的代码。
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
output_notebook()
from bokeh.layouts import column, row
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, Select, TextInput
def simple_app(doc):
p = figure(tools="", toolbar_location=None)
p = figure(tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")])
p.x_range.range_padding = p.y_range.range_padding = 0
r = p.image(image=[np.zeros((200,200))], x=0, y=0, dw=10, dh=10, palette="Spectral11", level="image")
select = Select(title="Select data", value="file2", options=['file1','file2'])
def update_data(attrname, old, new):
tdata = {"file1": np.random.rand(200,200)*3,
"file2": np.random.rand(200,200)*5.,
}
# reading files
cd = ColumnDataSource(data={'image': tdata[select.value]})
print(f"Selected {select.value}")
r.data_source = cd # here it potentially could be changed, but does not seem to work
select.on_change('value', update_data)
layout = column(row(select, width=200), row(p))
doc.add_root(layout)
show(simple_app)
解决方案
推荐阅读
- python - Pandas - 如何在每组数据帧中执行值与时间的 OLS 回归?
- python - 使用小数分隔符逗号读取 csv 的熊猫不会更改所有值
- c# - ExcelDNA 项目中的 Sandcastle 文档
- git - 有没有办法在 git 中轻松签出另一个分支?
- c# - 如何在 ComboBox C# 中填充多个文件名
- c++ - log4cxx 设置日志文件的文件权限
- python - 两个数组之间的逐行比较
- amazon-redshift - aws Glue / Redshift 的预过滤解决方案(在加载到 S3 之前)
- sql - 在现有范围右分区表中添加分区左边界
- javascript - 在 Javascript 中导出动态名称