def weightsChanged(self): """ Updates the application state if the weights/error bars for this model are changed - the GUI will automatically do this if you give it a new set of weights array, but not if they are changed in-place. """ weights = self.weights if 'errorplots' in self.trait_names(): #TODO:switch this to updating error bar data/visibility changing if self.errorplots is not None: self.plot.remove(self.errorplots[0]) self.plot.remove(self.errorplots[1]) self.errorbarplots = None if len(weights.shape)==2 and weights.shape[0]==2: xerr,yerr = 1/weights high = ArrayDataSource(self.scatter.index.get_data()+xerr) low = ArrayDataSource(self.scatter.index.get_data()-xerr) ebpx = ErrorBarPlot(orientation='v', value_high = high, value_low = low, index = self.scatter.value, value = self.scatter.index, index_mapper = self.scatter.value_mapper, value_mapper = self.scatter.index_mapper ) self.plot.add(ebpx) high = ArrayDataSource(self.scatter.value.get_data()+yerr) low = ArrayDataSource(self.scatter.value.get_data()-yerr) ebpy = ErrorBarPlot(value_high = high, value_low = low, index = self.scatter.index, value = self.scatter.value, index_mapper = self.scatter.index_mapper, value_mapper = self.scatter.value_mapper ) self.plot.add(ebpy) self.errorplots = (ebpx,ebpy) while len(weights.shape)>1: weights = np.sum(weights**2,axis=0) self.plot.data.set_data('weights',weights) self.plot.plots['data'][0].color_mapper.range.refresh() if self.weightsvary: if self.colorbar not in self.plotcontainer.components: self.plotcontainer.add(self.colorbar) self.plotcontainer.request_redraw() elif self.colorbar in self.plotcontainer.components: self.plotcontainer.remove(self.colorbar) self.plotcontainer.request_redraw()
def _get_or_create_datasource_imag(self, name): """ Returns the data source associated with the given name, or creates it if it doesn't exist. """ if name + '_imag' not in self.datasources: data = self.data.get_data(name) if type(data) in (list, tuple): data = array(data) if isinstance(data, ndarray): data = data.imag assert len(data.shape) == 1 ds = ArrayDataSource(data, sort_order="none") elif isinstance(data, AbstractDataSource): raise NotImplementedError ds = data else: raise ValueError("Couldn't create datasource for data of type " + \ str(type(data))) self.datasources[name + '_imag'] = ds return self.datasources[name + '_imag']
def _create_TracePlot_component(self): plot = DataView(border_visible=True) line = LinePlot(value=ArrayDataSource(self.Trace), index=ArrayDataSource(numpy.arange(len(self.Trace))), color='blue', index_mapper=LinearMapper(range=plot.index_range), value_mapper=LinearMapper(range=plot.value_range)) plot.index_range.sources.append(line.index) plot.value_range.sources.append(line.value) plot.add(line) plot.index_axis.title = 'index' plot.value_axis.title = 'Fluorescence [ counts / s ]' plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(plot)) self.TraceLine = line return plot
def test_reverse_construction(self): mapper = LinearMapper() r = DataRange1D() ds = ArrayDataSource() ary = array([1,2,3,4,5,6,7]) mapper.range = r mapper.low_pos = 1.0 mapper.high_pos = 7.0 r.add(ds) ds.set_data(ary) self.assert_(r.low == 1) self.assert_(r.high == 7) screen_pts = mapper.map_screen(array([1,3,7])) self.assert_(tuple(screen_pts) == (1.0, 3.0, 7.0)) return
def create_timechart_container(project): """ create a vplotcontainer which connects all the inside plots to synchronize their index_range """ # find index limits low = 1<<64 high = 0 for i in xrange(len(project.c_states)): if len(project.c_states[i].start_ts): low = min(low,project.c_states[i].start_ts[0]) high = max(high,project.c_states[i].end_ts[-1]) if len(project.p_states[i].start_ts): low = min(low,project.p_states[i].start_ts[0]) high = max(high,project.p_states[i].start_ts[-1]) for tc in project.processes: if len(tc.start_ts): low = min(low,tc.start_ts[0]) high = max(high,tc.end_ts[-1]) project.process_stats(low,high) if low > high: low=0 high=1 # we have the same x_mapper/range for each plots index_range = DataRange1D(low=low, high=high) index_mapper = LinearMapper(range=index_range,domain_limit=(low,high)) value_range = DataRange1D(low=0, high=project.num_cpu*2+project.num_process) value_mapper = LinearMapper(range=value_range,domain_limit=(0,project.num_cpu*2+project.num_process)) index = ArrayDataSource(array((low,high)), sort_order="ascending") plot = tcPlot(index=index, proj=project, bgcolor="white",padding=(0,0,0,40), use_backbuffer = True, fill_padding = True, value_mapper = value_mapper, index_mapper=index_mapper, line_color="black", render_style='hold', line_width=1) plot.lowest_i = low plot.highest_i = high project.on_trait_change(plot.invalidate, "plot_redraw") project.on_trait_change(plot.invalidate, "selected") max_process = 50 if value_range.high>max_process: value_range.low = value_range.high-max_process # Attach some tools plot.tools.append(tools.myPanTool(plot,drag_button='left')) zoom = tools.myZoomTool(component=plot, tool_mode="range", always_on=True,axis="index",drag_button=None, zoom_to_mouse=True,x_max_zoom_factor=float("inf"),x_min_zoom_factor=float("-inf")) plot.tools.append(zoom) plot.range_selection = tools.myRangeSelection(plot,resize_margin=3) plot.tools.append(plot.range_selection) plot.overlays.append(RangeSelectionOverlay(component=plot,axis="index",use_backbuffer=True)) axe = PlotAxis(orientation='bottom',title='time',mapper=index_mapper,component=plot) plot.underlays.append(axe) plot.options.connect(plot) plot.range_tools.connect(plot) return plot
def _create_HistPlot_component(self): plot = DataView(border_visible=True) line = LinePlot( index=ArrayDataSource(self.HistogramBins), value=ArrayDataSource(self.HistogramN), color='blue', #fill_color='blue', index_mapper=LinearMapper(range=plot.index_range), value_mapper=LinearMapper(range=plot.value_range)) plot.index_range.sources.append(line.index) plot.value_range.sources.append(line.value) plot.add(line) plot.index_axis.title = 'Fluorescence counts' plot.value_axis.title = 'number of occurences' plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(plot)) self.HistLine = line return plot
def __init__(self, model, ui, extension, parent): ''' Constructor ''' self.model = model self.ui = ui self.extension = extension self.parent = parent self.plots = {} self.renderers = {} self.hidden = False self.time_src = ArrayDataSource([]) self.container = VPlotContainer(bgcolor="white", fill_padding=True, border_visible=False, stack_order='top_to_bottom') self.setup_plots() self.pc = self.edit_traits(view='container_view', parent=parent, kind='subpanel').control parent.layout.addWidget(self.pc) self.pc.setParent(parent)
def _plot_container_default(self): index = np.arange(100) value = 100.0 * index self.value_ds = ArrayDataSource(value) self.index_ds = ArrayDataSource(index) self.horizontal_pos_ds = ArrayDataSource(10 * index) self.horizontal_index_ds = ArrayDataSource(index) self.int_index_ds = ArrayDataSource(index) self.int_val_ds = ArrayDataSource(index*1000) return create_plot(self.value_ds, self.index_ds, self.horizontal_pos_ds, self.horizontal_index_ds, self.int_val_ds, self.int_index_ds)
def __init__(self, model, ui, extension, parent): ''' Constructor ''' self.model = model self.ui = ui self.extension = extension self.parent = parent self.plots = {} self.renderers = {} self.hidden = False self.time_src = ArrayDataSource([]) self.container = VPlotContainer(bgcolor = "white", fill_padding=True, border_visible=False, stack_order = 'top_to_bottom') self.setup_plots() self.pc = self.edit_traits(view='container_view', parent=parent, kind='subpanel').control parent.layout.addWidget(self.pc) self.pc.setParent(parent)
def test_bounds(self): # ascending myarray = arange(10) sd = ArrayDataSource(myarray, sort_order="ascending") bounds = sd.get_bounds() self.assert_(bounds == (0,9)) # descending myarray = arange(10)[::-1] sd = ArrayDataSource(myarray, sort_order="descending") bounds = sd.get_bounds() self.assert_(bounds == (0,9)) # no order myarray = array([12,3,0,9,2,18,3]) sd = ArrayDataSource(myarray, sort_order="none") bounds = sd.get_bounds() self.assert_(bounds == (0,18)) return
def plot_circle(self, data, name=None, origin=None, **styles): print "plot_circle" if len(data) == 0: return if isinstance(data, basestring): data = (data, ) if name is None: name = self._make_new_plot_name() if origin is None: origin = self.default_origin if len(data) == 1: if self.default_index is None: # Create the default index based on the length of the first # data series value = self._get_or_create_datasource(data[0]) self.default_index = ArrayDataSource(arange( len(value.get_data())), sort_order="none") self.index_range.add(self.default_index) index = self.default_index else: index = self._get_or_create_datasource(data[0]) index_ = self._get_or_create_datasource_circle_real(data[1]) if self.default_index is None: self.default_index = index self.index_range.add(index_) data = data[1:] new_plots = [] for value_name in data: value = self._get_or_create_datasource(value_name) value_ = self._get_or_create_datasource_circle_imag(value_name) self.value_range.add(value_) # handle auto-coloring request if styles.get("color") == "auto": self._auto_color_idx = \ (self._auto_color_idx + 1) % len(self.auto_colors) styles["color"] = self.auto_colors[self._auto_color_idx] #styles["face_color"] = "green" imap = SmithMapper(range=self.index_range, stretch_data=self.index_mapper.stretch_data) vmap = SmithMapper(range=self.value_range, stretch_data=self.value_mapper.stretch_data) plot = SmithCircleRenderer(index=index, value=value, index_mapper=imap, value_mapper=vmap, bgcolor="white", **styles) print "circle:", vmap.range self.add(plot) new_plots.append(plot) self.plots[name] = new_plots return self.plots[name]
def plot(self, data, name=None, origin=None, **styles): """ Adds a new sub-plot using the given data and plot style. Parameters ========== data : string, tuple(string), list(string) The data to be plotted. The type of plot and the number of arguments determines how the arguments are interpreted: one item: (line/scatter) The data is treated as the value and self.default_index is used as the index. If **default_index** does not exist, one is created from arange(len(*data*)) two or more items: (line/scatter) Interpreted as (index, value1, value2, ...). Each index,value pair forms a new plot of the type specified. two items: (cmap_scatter) Interpreted as (value, color_values). Uses **default_index**. three or more items: (cmap_scatter) Interpreted as (index, val1, color_val1, val2, color_val2, ...) name : string The name of the plot. If None, then a default one is created (usually "plotNNN"). origin : string Which corner the origin of this plot should occupy: "bottom left", "top left", "bottom right", "top right" styles : series of keyword arguments attributes and values that apply to one or more of the plot types requested, e.g.,'line_color' or 'line_width'. Examples ======== :: plot("my_data", name="myplot", color=lightblue) plot(("x-data", "y-data")) plot(("x", "y1", "y2", "y3")) Returns ======= [renderers] -> list of renderers created in response to this call to plot() """ print "plot" if len(data) == 0: return if isinstance(data, basestring): data = (data, ) # TODO: support lists of plot types if name is None: name = self._make_new_plot_name() if origin is None: origin = self.default_origin if len(data) == 1: # Create the default freq based on the length of the first # data series value = self._get_or_create_datasource_real(data[0]) freq = ArrayDataSource(arange(len(value.get_data())), sort_order="none") #self.freq_range.add(self.default_index) if self.default_index is None: # Create the default index based the first data series value = self._get_or_create_datasource_real(data[0]) self.default_index = value self.index_range.add(self.default_index) index = self.default_index else: index = self._get_or_create_datasource(data[0]) index_ = self._get_or_create_datasource_real(data[1]) if self.default_index is None: self.default_index = index self.index_range.add(index_) data = data[1:] new_plots = [] for value_name in data: value = self._get_or_create_datasource(value_name) value_ = self._get_or_create_datasource_imag(value_name) self.value_range.add(value_) # handle auto-coloring request if styles.get("color") == "auto": self._auto_color_idx = \ (self._auto_color_idx + 1) % len(self.auto_colors) styles["color"] = self.auto_colors[self._auto_color_idx] imap = SmithMapper(range=self.index_range, stretch_data=self.index_mapper.stretch_data) vmap = SmithMapper(range=self.value_range, stretch_data=self.value_mapper.stretch_data) plot = SmithLineRenderer(index=index, value=value, index_mapper=imap, value_mapper=vmap, bgcolor="white", **styles) self.add(plot) new_plots.append(plot) self.plots[name] = new_plots return self.plots[name]
class Plots(HasTraits): ''' Main work horse. Model of the data. ''' container = Instance(VPlotContainer) container_view = View(Item('container', editor=ComponentEditor(), show_label=False, width=1000, height=400), width=1000, height=400, resizable=True) #*************************************__init__()************************************* def __init__(self, model, ui, extension, parent): ''' Constructor ''' self.model = model self.ui = ui self.extension = extension self.parent = parent self.plots = {} self.renderers = {} self.hidden = False self.time_src = ArrayDataSource([]) self.container = VPlotContainer(bgcolor="white", fill_padding=True, border_visible=False, stack_order='top_to_bottom') self.setup_plots() self.pc = self.edit_traits(view='container_view', parent=parent, kind='subpanel').control parent.layout.addWidget(self.pc) self.pc.setParent(parent) #*************************************update_plots()************************************* def update_plots(self, pc): ''' Args: Returns: Raises: ''' ann = pc.data_dict["annotations"] t0 = ann.get_value("START") t1 = ann.get_value("STOP") tug = ann.get_value("TURN_AROUND") delta = t1 - t0 total = delta.seconds + delta.microseconds * 10**(-6) self.time_src.set_data([0, total]) t2 = tug - t0 t2 = t2.seconds + t2.microseconds * 10**(-6) self.x_axis.labels = ["START", "TURN_AROUND", "5s", "STOP"] self.x_axis.positions = [0, t2, 5, total] for name, plot in self.plots.items(): plot_conactory = plot.plot_conactory res = pc.results[name[:-3]] # to remove the extension print res data_src = plot_conactory.datasources.get("index") data_src.set_data(res[0]) data_src = plot_conactory.datasources.get(name) data_src.set_data(res[1]) #*************************************create_plot()************************************* def create_plot(self, name, ylabel="", color="blue"): ''' Args: Returns: Raises: ''' p = PlotContainer(name, self, self.time_src) p.plot_conactory.y_axis.title = ylabel self.plots[name] = p p.plot_data.set_data(name, []) renderer, = p.plot_conactory.plot(("index", name), name=name, color=color, line_width=1.5) self.renderers[name] = renderer self.container.add(p.plot_conactory) #*************************************setup_plots()************************************* def setup_plots(self): ''' Args: Returns: Raises: ''' ext = self.extension if ext == "S2": color = "green" else: color = "blue" self.create_plot("AAE " + ext, ylabel="[ ]", color=color) self.create_plot("ARE " + ext, ylabel="[ ]", color=color) self.create_plot("Jerk " + ext, ylabel="[m/s2/s]", color=color) self.create_plot("SI " + ext, ylabel="[ ]", color=color) self.create_plot("VI " + ext, ylabel="[ ]", color=color) p = self.plots["VI " + ext] null_ds = ArrayDataSource([]) self.time_plot = LinePlot( index=self.time_src, value=null_ds, index_mapper=LinearMapper(range=DataRange1D(self.time_src)), value_mapper=LinearMapper(range=DataRange1D(null_ds)), color="black", border_visible=True, bgcolor="white", height=10, resizable="h", padding_top=50, padding_bottom=40, padding_left=50, padding_right=20) self.ticker = ScalesTickGenerator() self.x_axis = LabelAxis(self.time_plot, orientation="bottom", title="Time [sec]", label_rotation=0) #self.x_axis = PlotAxis(self.time_plot, orientation="bottom", tick_generator = self.ticker, title="Time [sec]") self.time_plot.underlays.append(self.x_axis) self.container.add(self.time_plot) # Add a range overlay to the miniplot that is hooked up to the range # of the main price_plot range_tool = RangeSelection(self.time_plot) self.time_plot.tools.append(range_tool) range_overlay = RangeSelectionOverlay(self.time_plot, metadata_name="selections") self.time_plot.overlays.append(range_overlay) range_tool.on_trait_change(self._range_selection_handler, "selection") self.range_tool = range_tool p.plot_conactory.index_range.on_trait_change(self._plot_range_handler, "updated") self.zoom_overlay = ZoomOverlay(source=self.time_plot, destination=p.plot_conactory) self.container.overlays.append(self.zoom_overlay) #*************************************set_inde_range()************************************* def set_index_range(self, low, high): ''' Args: Returns: Raises: ''' iterator = iter(self.renderers.values()) while True: try: curr = iterator.next() curr.index_range.low = low curr.index_range.high = high except StopIteration: break #*************************************set_bounds()************************************* def set_bounds(self, low, high): ''' Args: Returns: Raises: ''' iterator = iter(self.renderers.values()) while True: try: curr = iterator.next() curr.index_range.set_bounds(low, high) except StopIteration: break #*************************************_range_selection_handler()************************************* def _range_selection_handler(self, event): ''' Args: Returns: Raises: ''' # The event obj should be a tuple (low, high) in data space if event is not None: low, high = event self.set_index_range(low, high) else: self.set_bounds("auto", "auto") #*************************************_plot_range_handler()************************************* def _plot_range_handler(self, event): ''' Args: Returns: Raises: ''' if event is not None: low, high = event if "auto" not in (low, high): pass '''if low < self.df["Time"][0]: low = self.df["Time"][0] if high > self.df["Time"][self.counter-1]: high = self.df["Time"][self.counter-1] self.range_tool.selection = (low, high)''' #*************************************change_view()************************************* def change_view(self, plots_to_show): ''' Args: Returns: Raises: ''' temp = list(self.container.components) # to get a copy for plot in temp: #if type(plot).__name__ == 'Plot': self.container.remove(plot) plots_to_show.sort() for plot in plots_to_show: self.container.add(self.plots[plot + " " + self.extension].plot_conactory) self.container.add( self.time_plot ) # add the time_plot back last so it is on the bottom self.container.request_redraw() #*************************************hide()************************************* def hide(self): ''' Args: Returns: Raises: ''' self.hidden = True self.pc.hide() #*************************************unhide()************************************* def unhide(self): ''' Args: Returns: Raises: ''' self.hidden = False self.pc.show()
def test_data_size(self): # We know that ScalarData always returns the exact length of its data myarray = arange(913) sd = ArrayDataSource(myarray) self.assert_(len(myarray) == sd.get_size()) return
class Plots(HasTraits): ''' Main work horse. Model of the data. ''' container = Instance(VPlotContainer) container_view = View(Item('container', editor=ComponentEditor(), show_label=False, width = 1000, height = 400), width = 1000, height = 400, resizable=True) #*************************************__init__()************************************* def __init__(self, model, ui, extension, parent): ''' Constructor ''' self.model = model self.ui = ui self.extension = extension self.parent = parent self.plots = {} self.renderers = {} self.hidden = False self.time_src = ArrayDataSource([]) self.container = VPlotContainer(bgcolor = "white", fill_padding=True, border_visible=False, stack_order = 'top_to_bottom') self.setup_plots() self.pc = self.edit_traits(view='container_view', parent=parent, kind='subpanel').control parent.layout.addWidget(self.pc) self.pc.setParent(parent) #*************************************update_plots()************************************* def update_plots(self, pc): ''' Args: Returns: Raises: ''' ann = pc.data_dict["annotations"] t0 = ann.get_value("START") t1 = ann.get_value("STOP") tug = ann.get_value("TURN_AROUND") delta = t1 - t0 total = delta.seconds + delta.microseconds * 10**(-6) self.time_src.set_data([0, total]) t2 = tug-t0 t2 = t2.seconds + t2.microseconds * 10**(-6) self.x_axis.labels = ["START", "TURN_AROUND", "5s", "STOP"] self.x_axis.positions = [0, t2, 5, total] for name, plot in self.plots.items(): plot_conactory = plot.plot_conactory res = pc.results[name[:-3]] # to remove the extension print res data_src = plot_conactory.datasources.get("index") data_src.set_data(res[0]) data_src = plot_conactory.datasources.get(name) data_src.set_data(res[1]) #*************************************create_plot()************************************* def create_plot(self, name, ylabel="", color="blue"): ''' Args: Returns: Raises: ''' p = PlotContainer(name, self, self.time_src) p.plot_conactory.y_axis.title = ylabel self.plots[name] = p p.plot_data.set_data(name, []) renderer, = p.plot_conactory.plot(("index", name), name=name, color=color, line_width=1.5) self.renderers[name] = renderer self.container.add(p.plot_conactory) #*************************************setup_plots()************************************* def setup_plots(self): ''' Args: Returns: Raises: ''' ext = self.extension if ext == "S2": color = "green" else: color = "blue" self.create_plot("AAE " + ext, ylabel="[ ]", color=color) self.create_plot("ARE " + ext, ylabel="[ ]", color=color) self.create_plot("Jerk " + ext, ylabel="[m/s2/s]", color=color) self.create_plot("SI " + ext, ylabel="[ ]", color=color) self.create_plot("VI " + ext, ylabel="[ ]", color=color) p = self.plots["VI " + ext] null_ds = ArrayDataSource([]) self.time_plot = LinePlot(index = self.time_src, value = null_ds, index_mapper = LinearMapper(range=DataRange1D(self.time_src)), value_mapper = LinearMapper(range=DataRange1D(null_ds)), color = "black", border_visible = True, bgcolor = "white", height = 10, resizable = "h", padding_top=50, padding_bottom=40, padding_left=50, padding_right=20) self.ticker = ScalesTickGenerator() self.x_axis = LabelAxis(self.time_plot, orientation="bottom", title="Time [sec]", label_rotation=0) #self.x_axis = PlotAxis(self.time_plot, orientation="bottom", tick_generator = self.ticker, title="Time [sec]") self.time_plot.underlays.append(self.x_axis) self.container.add(self.time_plot) # Add a range overlay to the miniplot that is hooked up to the range # of the main price_plot range_tool = RangeSelection(self.time_plot) self.time_plot.tools.append(range_tool) range_overlay = RangeSelectionOverlay(self.time_plot, metadata_name="selections") self.time_plot.overlays.append(range_overlay) range_tool.on_trait_change(self._range_selection_handler, "selection") self.range_tool = range_tool p.plot_conactory.index_range.on_trait_change(self._plot_range_handler, "updated") self.zoom_overlay = ZoomOverlay(source=self.time_plot, destination=p.plot_conactory) self.container.overlays.append(self.zoom_overlay) #*************************************set_inde_range()************************************* def set_index_range(self, low, high): ''' Args: Returns: Raises: ''' iterator = iter(self.renderers.values()) while True: try: curr = iterator.next() curr.index_range.low = low curr.index_range.high = high except StopIteration: break #*************************************set_bounds()************************************* def set_bounds(self, low, high): ''' Args: Returns: Raises: ''' iterator = iter(self.renderers.values()) while True: try: curr = iterator.next() curr.index_range.set_bounds(low, high) except StopIteration: break #*************************************_range_selection_handler()************************************* def _range_selection_handler(self, event): ''' Args: Returns: Raises: ''' # The event obj should be a tuple (low, high) in data space if event is not None: low, high = event self.set_index_range(low, high) else: self.set_bounds("auto", "auto") #*************************************_plot_range_handler()************************************* def _plot_range_handler(self, event): ''' Args: Returns: Raises: ''' if event is not None: low, high = event if "auto" not in (low, high): pass '''if low < self.df["Time"][0]: low = self.df["Time"][0] if high > self.df["Time"][self.counter-1]: high = self.df["Time"][self.counter-1] self.range_tool.selection = (low, high)''' #*************************************change_view()************************************* def change_view(self, plots_to_show): ''' Args: Returns: Raises: ''' temp = list(self.container.components) # to get a copy for plot in temp: #if type(plot).__name__ == 'Plot': self.container.remove(plot) plots_to_show.sort() for plot in plots_to_show: self.container.add(self.plots[plot + " " + self.extension].plot_conactory) self.container.add(self.time_plot) # add the time_plot back last so it is on the bottom self.container.request_redraw() #*************************************hide()************************************* def hide(self): ''' Args: Returns: Raises: ''' self.hidden = True self.pc.hide() #*************************************unhide()************************************* def unhide(self): ''' Args: Returns: Raises: ''' self.hidden = False self.pc.show()
class OpticalAxisMainGUI(HasTraits): ''' classdocs ''' # data data_model = Instance(FieldData,()) # settings for the intensity input intensity_treshold = Float(1e-10) # plot container plot_container = Instance(Component) plot_size=(600,400) plot_item = Item('plot_container',editor=ComponentEditor(size=plot_size),show_label=False) # data sources for the plot index_ds = Instance(ArrayDataSource) value_ds = Instance(ArrayDataSource) horizontal_pos_ds = Instance(ArrayDataSource) horizontal_index_ds = Instance(ArrayDataSource) int_val_ds = Instance(ArrayDataSource) int_index_ds = Instance(ArrayDataSource) # Maya #mayavi = Instance(ScalarField3DPlot_GUI,()) #mayavi_item = Item('mayavi', show_label = False, style='custom') # acquire threads capture_thread=Instance(AcquireThread) # Buttons thread_control = Event button_label_tc = Str('Start acquisition') button_tc = Item('thread_control' ,show_label=False, editor=ButtonEditor(label_value='button_label_tc')) # Status Fields status_field = Str("Welcome\n This is multiline\n\n") item_status_field = Item('status_field', show_label=False, style='readonly') #prepare GUI (Items, Groups, ...) g1 = Group(button_tc, 'intensity_treshold', plot_item, item_status_field , label='Along Axis') #g2 = Group(mayavi_item, item_status_field, label='3D Plot') view = View(Tabbed(g1), width=800, resizable=True,) def _thread_control_fired(self): if self.capture_thread and self.capture_thread.isAlive(): self.capture_thread.wants_abort = True self.button_label_tc = 'Start acquisition' else: self.capture_thread=AcquireThread() self.capture_thread.wants_abort = False self.capture_thread.model = self.data_model self.capture_thread.gui = self self.capture_thread.int_treshold = self.intensity_treshold self.capture_thread.start() self.button_label_tc = 'Stop acquisition' def _plot_container_default(self): index = np.arange(100) value = 100.0 * index self.value_ds = ArrayDataSource(value) self.index_ds = ArrayDataSource(index) self.horizontal_pos_ds = ArrayDataSource(10 * index) self.horizontal_index_ds = ArrayDataSource(index) self.int_index_ds = ArrayDataSource(index) self.int_val_ds = ArrayDataSource(index*1000) return create_plot(self.value_ds, self.index_ds, self.horizontal_pos_ds, self.horizontal_index_ds, self.int_val_ds, self.int_index_ds) @on_trait_change('data_model.height') def update_plot(self,name,old,new): numpoints = new.size index = np.arange(numpoints) self.index_ds.set_data(index) self.value_ds.set_data(new) @on_trait_change('data_model.horizontal_pos') def update_horizontal_pos_plot(self, name, old, new): numpoints = new.size self.horizontal_index_ds.set_data(np.arange(numpoints)) self.horizontal_pos_ds.set_data(new) @on_trait_change('data_model.power_data') def update_power_data_plot(self,name, old, new): numpoints = new.size self.int_index_ds.set_data(np.arange(numpoints)) self.int_val_ds.set_data(new)
def setup_plots(self): ''' Args: Returns: Raises: ''' ext = self.extension if ext == "S2": color = "green" else: color = "blue" self.create_plot("AAE " + ext, ylabel="[ ]", color=color) self.create_plot("ARE " + ext, ylabel="[ ]", color=color) self.create_plot("Jerk " + ext, ylabel="[m/s2/s]", color=color) self.create_plot("SI " + ext, ylabel="[ ]", color=color) self.create_plot("VI " + ext, ylabel="[ ]", color=color) p = self.plots["VI " + ext] null_ds = ArrayDataSource([]) self.time_plot = LinePlot( index=self.time_src, value=null_ds, index_mapper=LinearMapper(range=DataRange1D(self.time_src)), value_mapper=LinearMapper(range=DataRange1D(null_ds)), color="black", border_visible=True, bgcolor="white", height=10, resizable="h", padding_top=50, padding_bottom=40, padding_left=50, padding_right=20) self.ticker = ScalesTickGenerator() self.x_axis = LabelAxis(self.time_plot, orientation="bottom", title="Time [sec]", label_rotation=0) #self.x_axis = PlotAxis(self.time_plot, orientation="bottom", tick_generator = self.ticker, title="Time [sec]") self.time_plot.underlays.append(self.x_axis) self.container.add(self.time_plot) # Add a range overlay to the miniplot that is hooked up to the range # of the main price_plot range_tool = RangeSelection(self.time_plot) self.time_plot.tools.append(range_tool) range_overlay = RangeSelectionOverlay(self.time_plot, metadata_name="selections") self.time_plot.overlays.append(range_overlay) range_tool.on_trait_change(self._range_selection_handler, "selection") self.range_tool = range_tool p.plot_conactory.index_range.on_trait_change(self._plot_range_handler, "updated") self.zoom_overlay = ZoomOverlay(source=self.time_plot, destination=p.plot_conactory) self.container.overlays.append(self.zoom_overlay)