我已将y轴的范围设置为固定范围
plot.y_axis.mapper.range.set(low_setting = ylim [0],high_setting = ylim [1])
然后,当用户使用缩放工具,并点击重置缩放键时,例如, ESC,y轴重置为紧密状态。但我的应用程序不知道这已经发生,并且无法再次正确设置轴限制。我正在使用BetterSelectingZoom工具。
我在BetterSelectingZoom的_reset_range_settings方法中看到,范围高和低设置被重置为BetterSelectingZoom._orig_low_setting,设置为'auto',但这会覆盖我在范围内设置的设置。 _orig_low_setting在创建时从范围中检索,稍后在实际完成缩放时不会更新。因此,如果在创建缩放工具后更改绘图的限制,您将遇到此问题。似乎在SelectZoomState上恢复后调用了_reset_range_settings,从而覆盖了缩放状态中的prev属性。这是一个错误吗?
为了使它工作,我可以在缩放工具中设置_orig_low_setting属性,或覆盖BetterSelectingZoom _reset_range_settings方法,但我感觉很难搞乱私人特征
代码示例:
plot = Plot(self._plot_data, padding=10, border_visible=True)
...
plot.bgcolor = 'white'
vertical_grid = PlotGrid(component=plot,
mapper=plot.index_mapper,
orientation='vertical',
line_color="gray",
line_style='dot',
use_draw_order=True)
horizontal_grid = PlotGrid(component=plot,
mapper=plot.value_mapper,
orientation='horizontal',
line_color="gray",
line_style='dot',
use_draw_order=True)
vertical_axis = PlotAxis(orientation='left',
mapper=plot.value_mapper,
use_draw_order=True, tick_label_font=font)
horizontal_axis = PlotAxis(orientation='bottom',
mapper=plot.index_mapper,
use_draw_order=True, tick_label_font=font)
horizontal_axis.tick_generator = XTickGenerator()
vertical_axis.tick_generator = YTickGenerator()
plot.underlays.append(vertical_grid)
plot.underlays.append(horizontal_grid)
# Have to add axes to overlays because
# we are backbuffering the main plot,
# and only overlays get to render in addition to the backbuffer.
plot.overlays.append(vertical_axis)
plot.overlays.append(horizontal_axis)
# Enable Pan and Zoom
pan = PanTool(plot, restrict_to_data=True,
constrain=False, constrain_direction="x",
constrain_key=None)
zoom = BetterSelectingZoom(component=plot,
tool_mode="box", restrict_domain=True,
always_on=True, drag_button="right",
x_min_zoom_factor=1, y_min_zoom_factor=1)
plot.tools.append(pan)
plot.overlays.append(zoom)
为了解决这个问题我做了这个
class NoRangeResetZoom(BetterSelectingZoom):
def _reset_range_settings(self):
pass
并且
zoom = NoRangeResetZoom(component=plot,
tool_mode="box", restrict_domain=True,
always_on=True, drag_button="right",
x_min_zoom_factor=1, y_min_zoom_factor=1)
plot.overlays.append(zoom)