盒子_变焦虚化的长宽比。

问题描述 投票:0回答:1

我正在绘制一张虚化的地图,我在工具栏中添加了工具。然而,我遇到的问题是 box_zoom 因为它允许放大一个扭曲地图的矩形。我如何固定地图的纵横比?box_zoom?

我找到了这个帖子,但不明白如何实现它。https:/discourse.bokeh.orgtkeep-a-fixed-aspect-ratio-when-zooming-with-box-tool35803。

我的代码如下。

# Create figure object.
p = figure(title = '2000-2020',
           title_location = 'above',
           plot_height = 400 ,
           plot_width = 400, 
           toolbar_location = 'above',
           tools = 'pan, wheel_zoom, box_zoom, reset',
           aspect_scale=0.05)
# Change font size on title

p.title.text_font_size = '12pt'
p.axis.visible = False
p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None
# Add patch renderer to figure.
neighbourhoods = p.patches('xs','ys', source = geosource,
                   fill_color = {'field' :'trees0020',
                                 'transform' : color_mapper},
                   line_color = 'black', 
                   line_width = 0.75, 
                   fill_alpha = 1)
# Create hover tool
p.add_tools(HoverTool(renderers = [neighbourhoods],
                      tooltips = [('Neighbourhood','@district'),
                                 ('Trees','@trees0020')]))
p.add_layout(color_bar, 'below')
p.toolbar.logo = None
# Remove the grey box around the plot
p.outline_line_color = None

show(p)
python bokeh
1个回答
1
投票

同样的方式,你已经做了它与 HoverTool - 去掉 box_zoom 来自 tools 争论,只需调用

from bokeh.models import BoxZoomTool

p.add_tools(BoxZoomTool(match_aspect=True))
© www.soinside.com 2019 - 2024. All rights reserved.