box_zoom 散景的纵横比
Aspect ratio for box_zoom bokeh
我正在散景中绘制地图,我在工具栏中添加了工具。但是我在使用 box_zoom
时遇到了问题,因为它允许放大矩形,这会扭曲地图。如何修正 box_zoom
?
的纵横比
我找到了这个线程,但不明白如何实现它:https://discourse.bokeh.org/t/keep-a-fixed-aspect-ratio-when-zooming-with-box-tool/3580/3
我的代码如下:
# 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)
与您在 HoverTool
中所做的相同 - 从 tools
参数中删除 box_zoom
并调用
from bokeh.models import BoxZoomTool
p.add_tools(BoxZoomTool(match_aspect=True))
我正在散景中绘制地图,我在工具栏中添加了工具。但是我在使用 box_zoom
时遇到了问题,因为它允许放大矩形,这会扭曲地图。如何修正 box_zoom
?
我找到了这个线程,但不明白如何实现它:https://discourse.bokeh.org/t/keep-a-fixed-aspect-ratio-when-zooming-with-box-tool/3580/3
我的代码如下:
# 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)
与您在 HoverTool
中所做的相同 - 从 tools
参数中删除 box_zoom
并调用
from bokeh.models import BoxZoomTool
p.add_tools(BoxZoomTool(match_aspect=True))