我想使用 chaco 工具ScatterInspector
和/或ScatterInspectorOverlay
enaml。我已经设置了一个非常简单的控制器和视图(下面的源代码),但无法确定如何进行。我尝试遵循我发现的最小和旧示例,但没有成功。
如果我取消注释覆盖部分ScatterInspectorOverlay
,代码将无法运行
文件“.../chaco/scatter_inspector_overlay.py”,第 51 行,如果不是 plot 或不是 plot.index 或不是 getattr(plot,“value”,True):
如果我注释掉覆盖部分,我当然不会得到我想要的覆盖行为,而且在移动鼠标时,得到
文件“.../chaco/tools/scatter_inspector.py”,第 48 行,在 normal_mouse_move index = plot.map_index((event.x, event.y), threshold=self.threshold)
view.enaml 来源:
from enaml.widgets.api import (
Window, Container, EnableCanvas,
)
enamldef ScatterView(Window):
attr controller
title = "Scatter Inspector Test"
initial_size = (640,480)
Container:
EnableCanvas:
component = controller.scatter_plot
控制器.py 来源:
import enaml
from enaml.stdlib.sessions import show_simple_view
from traits.api import HasTraits, Instance
from chaco.api import Plot, ArrayPlotData, ScatterInspectorOverlay
from chaco.tools.api import ScatterInspector
from numpy import linspace, sin
class ScatterController(HasTraits):
scatter_plot = Instance(Plot)
def _scatter_plot_default(self):
# data
x = linspace(-14, 14, 100)
y = sin(x) * x**3
plotdata = ArrayPlotData(x = x, y = y)
# plot
scatter_plot = Plot(plotdata)
renderer = scatter_plot.plot(("x", "y"), type="scatter", color="red")
# inspector
scatter_plot.tools.append(ScatterInspector(scatter_plot))
# overlay
# scatter_plot.overlays.append( ScatterInspectorOverlay(
# scatter_plot,
# hover_color = 'red',
# hover_marker_size = 6,
# selection_marker_size = 6,
# selection_color = 'yellow',
# selection_outline_color='purple',
# selection_line_width = 3
# ))
#return
return scatter_plot
if __name__ == "__main__":
with enaml.imports():
from view import ScatterView
main_controller = ScatterController()
window = ScatterView(controller=ScatterController())
show_simple_view(window)