python - 散景删除网格图中元素之间的空间
问题描述
我有一个 Bokeh 应用程序bokeh==1.0.1
(我正在使用sizing_mode='stretch_both'
. 如何消除小部件行和其他图形面板之间的空白?这是一个屏幕截图:
我为小部件创建了一个布局,如下所示:
blank_button = bkm.widgets.RadioButtonGroup()
blank_wb = widgetbox(blank_button, width=50, height=100, sizing_mode='fixed') # placeholder for space
date_slider_wb = widgetbox(date_slider, width=400, height=100, sizing_mode='fixed')
apply_button = bkm.widgets.Button(label="APPLY")
apply_wb = widgetbox(apply_button, width=100, height=100, sizing_mode='fixed')
hor_layout_date_slider = (
row(
column(blank_wb),
column(date_slider_wb),
column(apply_wb),
)
)
然后我包括hor_layout_date_slider
在一个gridplot
:
grid = gridplot(
children = [
hor_layout_date_slider,
airtemp_fig,
windspeed_fig,
winddir_fig,
interval_fig,
precip_fig,
pressure_fig
],
ncols=1,
sizing_mode='stretch_both',
merge_tools=False,
)
curdoc().add_root(grid)
我正在使用散景服务器并将散景文档呈现在我的 html 模板中的单个 div 中:
<div class="placeholderbokehapp rounded" id="tbc-id">
<script src="http://localhost:5858/stormtracker_bokehapp/autoload.js?bokeh-autoload-element=1000&bokeh-app-path=/stormtracker_bokehapp&bokeh-absolute-url=http://localhost:5858/stormtracker_bokehapp&resources=none" id="1000"></script>
</div>
作为一种尝试性的破解解决方案,我已经能够通过自定义 css 规则来定义包含 div 的高度hor_layout_date_slider
,但是对于这个元素仍然存在一个“占位符”(我无法使用检查元素访问)。
我还尝试使用仅包含滑块的简单小部件框(未定义高度和宽度并使用sizing_mode='stretch_both'
),而不是hor_layout_date_slider
上面定义的完整框。但是,这会导致滑块元素后面出现相同的空白。
奇怪的是,这个问题不会发生sizing_mode='scale_width'
(滑块在布局中很紧)。
使用时是否有我不知道的散景设置来控制此布局中的间距sizing_mode='stretch_both'
?
更新:
如果我将小部件和网格分别添加为:
curdoc().add_root(hor_layout_date_slider)
curdoc().add_root(grid)
然后在第一个图形面板下方呈现小部件(您可以在下面的屏幕截图中看到滑块小部件的一部分)。
解决方案
sizing_mode
在网格或选项卡中嵌套列和行时效果不佳。只需将滑块从网格中取出并单独添加到根。
from bokeh.plotting import figure, curdoc
from bokeh.layouts import row, gridplot
from bokeh.models.widgets import Slider, RadioButtonGroup, Button
blank_button = RadioButtonGroup()
date_slider = Slider(start = 1, end = 10, value = 5)
apply_button = Button(label = "APPLY")
hor_layout_date_slider = row(blank_button, date_slider, apply_button)
airtemp_fig = figure()
windspeed_fig = figure()
grid = gridplot(children = [airtemp_fig, windspeed_fig],
ncols = 1,
sizing_mode = 'stretch_both',
merge_tools = False)
curdoc().add_root(hor_layout_date_slider)
curdoc().add_root(grid)
推荐阅读
- php - php如何表示浮点数
- asp.net-core - 使用 Ocelot 为 Web 套接字连接设置 CORS 策略
- java - 类路径包含多个 SLF4J 绑定 - 我没有找到加倍的条目
- r - 在ggplotly生成的工具提示中抑制变量名称
- mysql - 使用映射自定义子域时,Google Cloud Run 失去了与 Mysql 的连接
- amazon-web-services - aws如何管理对ec2的iam ssh访问
- flutter - Flutter widget that scales it's child before laying it out?
- amazon-web-services - Error in Call to Sagemaker Endpoint with Lambda and API Gateway
- ios - 我怎样才能提高它的性能......为什么没有 LazyZStack 这样的东西?
- firebase - 如何在 Firestore 集合中检索文档的 documentId,以便在返回对象流的 getter 中使用它