0

我对 chaco 有这个问题。

在图中,我需要选择一些点(是我生成的点)。这一点,我可以用两个工具进行选择:RangenSelection 和 ScatterInspector。如果我只使用一个工具,代码运行良好,我可以检测到我选择的点,但是当我使用这两个工具时,两个工具都写了相同的元数据名称:selections. 这是代码中最重要的部分:

#this are all the tools.append
my_plot.tools.append(ScatterInspector(my_plot, selection_mode="toggle", persistent_hover=False))
my_plot.overlays.append(
        ScatterInspectorOverlay(my_plot,
            hover_color = "transparent",
            hover_marker_size = 10,
            hover_outline_color = "purple",
            hover_line_width = 2,
            selection_marker_size = 8,
            selection_color = "red")
        )

my_plot.tools.append(RangeSelection(my_plot, left_button_selects = False, rigth_button_selects = True, auto_handle_event = False))
my_plot.overlays.append(RangeSelectionOverlay(component=my_plot)) 

my_plot.tools.append(PanTool(my_plot))
my_plot.overlays.append(ZoomTool(my_plot, drag_button="right"))

return plot

#the rest of the code

def _metadata_handler(self):
    sel_indices = self.index_datasource.metadata.get('selections', [])
    su = self.index_datasource.metadata.get('annotations', [])
    print su
    print "Selection indices:", sel_indices

def _plot_default(self):
    plot = _create_plot_component()

    # Retrieve the plot hooked to the tool.
    my_plot = plot.plots["my_plot"][0]

    # Set up the trait handler for the selection
    self.index_datasource = my_plot.index
    self.index_datasource.on_trait_change(self._metadata_handler,
                                          "metadata_changed")

    return plot

当我运行代码并查看 中的内容时annotations,总是为空。但是在selections 使用这两种工具编写的代码中,这会产生错误。我如何告诉一些工具在哪里元数据密钥写入?

谢谢你的帮助。

4

1 回答 1

0

解决方案放入metadata_name="annotations"RangeSelection放入RangeSelectionOverlay

于 2013-07-29T00:22:31.287 回答