2013-07-24 1 views
0

나는 Chaco 도서관에서 일하고있다. 대화 형 플롯을 만들고이 플롯에서 chaco.tools.api RangeSelection을 사용하여이 부분을 선택할 수 있습니다. 자, 저는이 사각형이 어떤 위치에 있는지 알고 있습니다. 다음 코드를 통해 필요한 모든 것을 할 수 있지만 다음과 같은 오류가 발생합니다. (오류에 내가 nedd에 사각형의 포인트입니다)대화 형 플롯 Chaco, 특이한 형질로 인한 알림

# 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() 

그리고이 오류의 일부입니다 : 오류, 나는에 포인트 nedd selection_masks이 코드입니다

있습니다

Exception occurred in traits notification handler for object: <chaco.array_data_source.ArrayDataSource object at 0x66a94d0>, trait: metadata_changed, old value: <undefined>, new value: True 
Traceback (most recent call last): 
    File "/home/franco/Python/Canopy/appdata/canopy-1.0.3.1262.rh5-x86_64/lib/python2.7/site-packages/traits/trait_notifiers.py", line 521, in rebind_call_1 
    self.dispatch(getattr(obj(), self.name), new) 
    File "/home/franco/Python/Canopy/appdata/canopy-1.0.3.1262.rh5-x86_64/lib/python2.7/site-packages/traits/trait_notifiers.py", line 455, in dispatch 
handler(*args) 
    File "/home/franco/Desktop/Proyecto/Codigo/analisis_mas_range_relections.py", line 59, in _selections_changed 
    selections = event["selections"] 
TypeError: 'bool' object has no attribute '__getitem__' 
Exception occurred in traits notification handler for object: <chaco.array_data_source.ArrayDataSource object at 0x66a94d0>, trait: metadata_changed, old value: <undefined>, new value: True 

#the error continue but is the same error change the selection_masks.... 

TypeError: 'bool' object has no attribute '__getitem__' 
Exception occurred in traits notification handler for object: <chaco.array_data_source.ArrayDataSource object at 0x6758290>, trait: metadata_changed, old value: <undefined>, new value: {'selection_masks': (-0.5953709619238516, 10.991581102204394)} 

#the selection_masks are the point to I need 

덕분에

+0

내가 게시 한 코드가 실행 한 코드라고 생각하지 않습니다. 코드에 첫 번째 추적에서 'corr_index = self.corr_renderer.index' 라인에 해당하는 라인이 없습니다. 여기서 무슨 일이 일어나고 있는지 명확히 할 수 있습니까? –

+0

로버트, 예전 코드의 오류를 넣었습니다. 내 질문을 편집합니다. 감사합니다 –

답변

1

나는 처음 역 추적이가 여기에 게시되지 않은 코드를 인용 표시하기 때문에 어디에서 오는 모르겠어요. 그러나 두 번째 역 추적은 명확합니다.

metadata_changedEvent에는 메타 데이터 사전이 할당되지 않습니다. 적어도 항상 그렇지는 않습니다. 메타 데이터를 수정하는 도구는 수년 동안 일관되게 작성되지 않았습니다. 대신 메타 데이터 사전을 데이터 소스에서 직접 가져와야합니다.

+0

Robert, 저는 Chaco에서 매우 새로운 사용자입니다. 메타 데이터 사전에 대해서는 잘 이해할 수 없습니다. 나는 이것에 관해 어디에서 갈 수 있느냐? 또는 몇 가지 예를 어디서 볼 수 있습니까? 시간과 도움에 감사드립니다. –

+1

'self.times_ds.metadata'는 당신이보아야 할 메타 데이터 사전이다. '_selections_changed()'메쏘드에서'event' 대신에 그것을 사용하십시오 (무제한이되도록 변경할 수 있습니다). 메타 데이터 사전은 당신이보고 싶은 것을 담고있는''selections'' 항목을 가질 것입니다. –

+0

도와 주신 Thanls Robert. 위의 코드를 실행하기 위해서는'def _selections_changed (self) :'sel_indices = self.times_ds.metadata.get ('selections', [])'을 변경하면됩니다 : –