我想将chaco工具ScatterInspector
和/或ScatterInspectorOverlay
与enaml一起使用。我已经设置了一个非常简单的控制器和视图(下面的源代码),但无法确定如何继续。我没有成功地遵循我发现的最小和最旧的例子。
如果我取消注释ScatterInspectorOverlay
的重叠部分,则代码无法与
文件“... / chaco / scatter_inspector_overlay.py”,第51行,在叠加中如果不是绘图或不是plot.index或不是getattr(plot,“value”,True):
如果我注释掉叠加部分,我当然不会得到我想要的叠加行为,而且,在移动鼠标时,得到
文件“... / chaco / tools / scatter_inspector.py”,第48行,在normal_mouse_move中索引= plot.map_index((event.x,event.y),threshold = self.threshold)
view.enaml source:
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
controller.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)
答案 0 :(得分:2)
我上面代码的问题在于我将ScatterInspector
添加到scatter_plot
而不是renderer
,并且我错过了[0]
索引来获取{{1} }}
renderer
,其中显示了如何执行此操作。
使用controller.py:
when_hover_or_selection_changes