交互式绘图Chaco,traits通知中出现异常

2024-04-20 01:21:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我在查科图书馆工作。我做了一个交互式的图,在这个图中,用查科工具.api范围选择,我可以选择其中的一部分。现在,我想知道这个长方形在什么位置。有了下面的代码,我可以做所有我需要的,但我有以下错误,为什么??在错误中,指向I nedd的点是选择掩码

代码如下:

# Major library imports
from numpy import arange
from scipy.special import jn

# Enthought library imports
from enable.api import Component, ComponentEditor
from traits.api import HasTraits, Instance, Any, on_trait_change
from traitsui.api import Item, Group, View

# Chaco imports
from chaco.api import create_line_plot, add_default_axes, add_default_grids
from chaco.tools.api import RangeSelection, RangeSelectionOverlay

# # Create the Chaco plot.
def _create_plot_component(self):

    numpoints = 100
    low = -5
    high = 15.001
    x = arange(low, high, (high-low)/numpoints)

    # Plot a bessel function
    y = jn(0, x)
    plot = create_line_plot((x,y), color=(0,0,1,1), width=2.0, index_sort="ascending")
    plot.active_tool = RangeSelection(plot, left_button_selects = True,     auto_handle_event = False)
    plot.overlays.append(RangeSelectionOverlay(component=plot))
    plot.bgcolor = "white"
    plot.padding = 50
    add_default_grids(plot)
    add_default_axes(plot)
    self.times_ds = plot.index
    self.times_ds.on_trait_change(self._selections_changed, 'metadata_changed')

    return plot

# Attributes to use for the plot view.
size=(600,500)
title="Simple line plot"

class Demo(HasTraits):
    times_ds = Any()
    plot = Instance(Component)
    corr_renderer = Any()

    traits_view = View(
                    Group(
                        Item('plot', editor=ComponentEditor(size=size),
                             show_label=False),
                        orientation = "vertical"),
                    resizable=True, title=title,
                    width=size[0], height=size[1]
                    )

    def _plot_default(self):
         return _create_plot_component(self)

    def _selections_changed(self, event):
        selections = event["selections"]
        low, high = selections
        print low, high

demo = Demo()
if __name__ == "__main__":
    demo.configure_traits()

这是错误的一部分(在错误中是矩形的点到内德)

^{pr2}$

谢谢


Tags: fromimportselfaddapidefaultsizeplot
1条回答
网友
1楼 · 发布于 2024-04-20 01:21:28

我不确定第一次回溯是从哪里来的,因为它似乎引用了没有发布在这里的代码。然而,第二次回溯是明确的。在

metadata_changedEvent没有被分配元数据字典。或者至少不总是这样。这些年来,修改元数据的工具一直不一致。只需直接从数据源获取元数据字典。在

相关问题 更多 >