我试图在一个原点设置为'左上角'的查科图中使用PanTool和ZoomTool,但这些工具的行为不像预期的那样。平移朝相反的方向移动,框缩放不一定缩放到突出显示的区域。示例代码为:
plot.plot((x_key, y_key), origin='top left')
plot.tools.append(PanTool(plot))
plot.overlays.append(ZoomTool(plot, tool_mode='box', always_on=False))
如果origin='top left'
被删除,平移和缩放行为是我所期望的。
这是一个非常晚的回复,但基本上需要在主Plot
实例上设置原点,而不是调用其plot
方法。(初始化Plot
时设置的origin
也传递给plot
)
import numpy as np
from enable.api import Component, ComponentEditor
from traits.api import HasTraits, Instance
from traitsui.api import UItem, Group, View
from chaco.api import ArrayPlotData, Plot
from chaco.tools.api import PanTool, ZoomTool
class Demo(HasTraits):
plot = Instance(Component)
traits_view = View(
Group(
UItem('plot', editor=ComponentEditor(size=(900, 500))),
),
)
def _plot_default(self):
x = np.linspace(-2.0, 10.0, 100)
data = ArrayPlotData(x=x, y=np.sin(x))
# This works
plot = Plot(data, origin='top left')
plot.plot(('x', 'y'))
# This doesn't
# plot = Plot(data)
# plot.plot(('x', 'y'), origin='top left')
plot.tools.append(PanTool(plot))
zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
plot.overlays.append(zoom)
return plot
if __name__ == "__main__":
demo = Demo()
demo.configure_traits()