def trait_view(self, view): """ Build the view. The local namespace is """ return View(VGroup( Item('data_file', style='simple', label="HDF file to load"), HSplit( Item('ts_plot', editor=ComponentEditor(size=(400, 600)), show_label=False), VGroup( Item('tool_chooser', show_label=True, label="Choose tool"), Item('ts1_chooser', label="TS 1"), Item('ts2_chooser', label="TS 2", visible_when="tool_chooser in ['%s']" % CORRELATION), Item('ma_window_size', label="MA window size", visible_when="tool_chooser in ['%s']" % MA), Item('ts_analysis_plot', editor=ComponentEditor(size=(400, 600)), show_label=False), Item('ts_analysis_details', show_label=False, style='readonly', visible_when=("tool_chooser in ['%s']" % CORRELATION))), ), ), title='Time-series plotter and analyzer', width=1300, height=800, resizable=True)
class Demo(HasTraits): lodpi = Instance(Component) hidpi = Instance(Component) traits_view = View( HGroup( HGroup( UItem( "lodpi", editor=ComponentEditor(high_resolution=False), width=250, height=250, ), ), HGroup( UItem( "hidpi", editor=ComponentEditor(high_resolution=True), width=250, height=250, ), ), ), resizable=True, title="HiDPI Example", ) def _lodpi_default(self): return MyComponent(quote="Pixelated") def _hidpi_default(self): return MyComponent(quote="Smooth")
class Demo(HasTraits): filled = Instance(Component) horizon = Instance(Component) traits_view = View( Group( Item('filled', editor=ComponentEditor(size=filled_size), show_label=False), Item('horizon', editor=ComponentEditor(size=horizon_size), show_label=False), orientation = "vertical"), resizable=False, title=title, width=filled_size[0], height=filled_size[1]+horizon_size[1], )
class Demo(HasTraits): vu = Instance(VUMeter) traits_view = View( VGroup( Group( UItem("vu", editor=ComponentEditor(size=(60, 60)), style="custom")), Item( "object.vu.percent", editor=RangeEditor(low=0.0, high=200.0, mode="slider"), ), ), "_", VGroup( Item( "object.vu.angle", label="angle", editor=RangeEditor(low=0.0, high=89.0, mode="slider"), ), Item( "object.vu._beta", editor=RangeEditor(low=0.0, high=1.0, mode="slider"), ), ), width=450, height=380, title="VU Meter", resizable=True, )
class Demo(HasTraits): plot_data = Instance(DataFramePlotData) plot = Instance(Component) traits_view = View(Group( Item('plot', editor=ComponentEditor(size=(900, 500)), show_label=False), orientation="vertical", ), resizable=True, title="pandas data example") def _plot_data_default(self): # Create a DataFrame with plottable data index = linspace(-2.0, 10.0, 100) df = DataFrame(index=index) for i in range(5): name = "y" + str(i) df[name] = jn(i, index) plot_data = DataFramePlotData(data_frame=df) return plot_data def _plot_default(self): plot = Plot(self.plot_data, padding=50) plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red") plot.plot(("index", "y3"), name="j_3", color="blue") plot.x_axis.title = "index" plot.y_axis.title = "j_n" return plot
class DataChooser(HasTraits): plot = Instance(Plot) data_name = Enum("jn0", "jn1", "jn2") # default view for a traits class traits_view = View( Item('data_name', label="Y data"), Item('plot', editor=ComponentEditor(), show_label=False), width=800, height=600, resizable=True, title="Data Chooser") def _plot_default(self): x = linspace(-5, 10, 100) self.data = {"jn0": jn(0, x), "jn1": jn(1, x), "jn2": jn(2, x)} self.plotdata = ArrayPlotData(x = x, y = self.data["jn0"]) plot = Plot(self.plotdata) plot.plot(("x", "y"), type="line", color="blue") return plot # by default Enum trait displayed as a drop down menu def _data_name_changed(self): self.plotdata.set_data("y", self.data[self.data_name])
class Demo(HasStrictTraits): range_tool = Any select = Button("Select") view = View( VGroup( UItem('plot', editor=ComponentEditor()), UItem('select') ) ) plot = Instance(Component) def _plot_default(self): plot_data = ArrayPlotData( x=np.linspace(0, 1, 10), y=np.linspace(0, 1, 10) ) plot = Plot(plot_data) r, = plot.plot(("x", "y")) range_tool = RangeSelection(r) r.overlays.append(RangeSelectionOverlay(axis='index', component=r)) r.tools.append(range_tool) self.range_tool = range_tool return plot def _select_changed(self): self.range_tool.selection = (0.2, 0.4)
class Plots(HasTraits): composite_plot = Instance(Component) traits_view = View(Group(Item('composite_plot', editor=ComponentEditor(), show_label=False), orientation="vertical"), resizable=True, title="Two Chaco Plots") def _composite_plot_default(self): x_line = np.linspace(-14, 14, 100) y_line = np.sin(x_line) * x_line**3 x = np.linspace(0, 10, 51) y = np.linspace(0, 5, 51) X, Y = np.meshgrid(x, y) z = np.exp(-(X**2 + Y**2) / 100) plotdata = ArrayPlotData(x=x_line, y=y_line, zdata=z[:-1, :-1]) line_plot = Plot(plotdata) line_plot.plot(('x', 'y'), type='line', color='blue') img_plot = Plot(plotdata) img_plot.img_plot("zdata", xbounds=x, ybounds=y, colormap=jet) cp = VPlotContainer() cp.add(img_plot) cp.add(line_plot) return cp
class LegendWindow(HasTraits): plot = Instance(OverlayPlotContainer) traits_view = View( UItem('plot', editor=ComponentEditor(bgcolor='white', width=500, height=500), show_label=False, resizable=True), title='Legend', scrollable=True, ) def __init__(self,legend): super(LegendWindow,self).__init__() self.legend = self.add_legend(legend) def _plot_default(self): self.container = OverlayPlotContainer(bgcolor="white", padding=10) self.container.add(self.legend) return self.container def get_legend(self): if self.legend: return self.legend def add_legend(self, legend): legend.set(component=None, padding=10, error_icon='blank', visible=True, resizable='hv', clip_to_component=True) return legend
def default_traits_view(self): view = KromView( HGroup( VGroup( Group( Item("select_all_collections", label="All"), UItem('displayed_log_collection_names', editor=CheckListEditor( values=self._all_log_collection_names), style='custom'), HGroup( UItem("color_editor"), ), label='Experiments/Simulations', show_border=True, ), Group( UItem('displayed_log_family_names', editor=CheckListEditor( values=self._all_log_family_names, format_func=lambda a: a), style='custom'), label='Plot Grouping', show_border=True, ), visible_when='_show_control' ), VGroup( UItem('_container', editor=ComponentEditor(), show_label=False), show_border=True, ), ), title="Chromatogram Plot", ) return view
class Demo(HasTraits): plot = Instance(Component) scatter_renderer = Instance(Component) alpha = DelegatesTo('scatter_renderer') traits_view = View(Group(Item('plot', editor=ComponentEditor(size=size, bgcolor=bg_color), show_label=False), Group( Item('alpha', editor=RangeEditor(low=0.0, high=1.0)), ), orientation="vertical"), resizable=True, title=title) def _plot_default(self): return _create_plot_component() def _scatter_renderer_default(self): renderer = _create_scatter_renderer(self.plot) return renderer
class ContainerExample(HasTraits): plot = Instance(HPlotContainer) traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False), width=1000, height=600, resizable=True, title="Chaco Plot") def _plot_default(self): x = linspace(-14, 14, 100) y = sin(x) * x**3 plotdata = ArrayPlotData(x=x, y=y) scatter = Plot(plotdata) scatter.plot(("x", "y"), type="scatter", color="blue") line = Plot(plotdata) line.plot(("x", "y"), type="line", color="blue") container = HPlotContainer(scatter, line) container.spacing = 0 scatter.padding_right = 0 line.padding_left = 0 line.y_axis_orientation = "right" return container
class GridContainerExample(HasTraits): plot = Instance(GridPlotContainer) traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False), width=1000, height=600, resizable=True) def _plot_default(self): # Create a GridContainer to hold all of our plots: 2 rows, 3 columns container = GridPlotContainer(shape=(2, 3), spacing=(10, 5), valign='top', bgcolor='lightgray') pd = ArrayPlotData(data=np.arange(36).reshape(6, 6)) plots = [] renderers = [] for i in range(6): plot = Plot(pd) r, = plot.img_plot("data") plots.append(plot) renderers.append(r) add_tools(r) # Add to the grid container container.add(plot) share_attr(plots, "range2d") share_attr([rend.index_mapper for rend in renderers], "range") return container
def default_traits_view(self): prod_comp_names = self.model.all_data.keys() time_slice_max = self.model.active_anim_data.columnliqZ.shape[2] - 1 return View( VGroup( HGroup( Item('model.product_component', label='Component', editor=EnumEditor(values=prod_comp_names)), Spring(), Item("time_description", style="readonly", show_label=False), Spring(), Item("model.simulation_name", style="readonly", label="Simulation"), ), Item('model.time_slice', label='Time slice', editor=RangeEditor(low=0, high=time_slice_max, mode='slider')), HGroup( UItem('model.plot', editor=ComponentEditor(), show_label=False), ), show_border=True, ), resizable=True, title="Animation Plot", width=1000, height=800, )
class DoubleScatterView(HasTraits): sv1=Instance(ScatterView) sv2=Instance(ScatterView) plot1=Instance(Plot) plot2=Instance(Plot) totalplot = Instance(Component) traits_view = View( Group( Item('totalplot', editor=ComponentEditor(), show_label=False), # Item('plot1',editor=ComponentEditor()), # orientation = "vertical"), ),resizable=True, title='Test' ) # def _totalplot_default(self): # return self.create_plots() def create_plots(self): container = HPlotContainer() container.add(self.plot1) container.add(self.plot2) self.totalplot=container def update(self, sv1, sv2): self.sv1=sv1 self.sv2=sv2 self.plot1=self.sv1.sigplot self.plot2=self.sv2.sigplot self.create_plots()
class Demo(HasTraits): plot = Instance(Component) controller = Instance(TimerController, ()) timer = Instance(Timer) 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], handler=DemoHandler ) def __init__(self, **traits): super(Demo, self).__init__(**traits) self.plot = _create_plot_component(self.controller) def edit_traits(self, *args, **kws): # Start up the timer! We should do this only when the demo actually # starts and not when the demo object is created. self.timer = Timer(20, self.controller.onTimer) return super(Demo, self).edit_traits(*args, **kws) def configure_traits(self, *args, **kws): # Start up the timer! We should do this only when the demo actually # starts and not when the demo object is created. self.timer = Timer(20, self.controller.onTimer) return super(Demo, self).configure_traits(*args, **kws)
class Demo(HasTraits): plot = Instance(Component) traits_view = View(Group(Item('plot', editor=ComponentEditor(size=size), show_label=False), orientation="vertical"), resizable=True, title=title) def _selection_changed(self): mask = self.index_datasource.metadata['selections'] print("New selection: ") print(compress(mask, arange(len(mask)))) # Ensure that the points are printed immediately: sys.stdout.flush() def _plot_default(self): plot = _create_plot_component() # Retrieve the plot hooked to the RectangularSelection tool. my_plot = plot.plots["my_plot"][0] rect_selection = my_plot.active_tool # Set up the trait handler for the selection self.index_datasource = my_plot.index rect_selection.on_trait_change(self._selection_changed, 'selection_changed') return plot
class Demo(HasTraits): plot = Instance(Component) traits_view = View(VGroup(HGroup(spring, Label('Click point to select/unselect'), spring), Item('plot', editor=ComponentEditor(size=size, bgcolor=bg_color), show_label=False), orientation="vertical"), resizable=True, title=title) def _metadata_handler(self): sel_indices = self.index_datasource.metadata.get('selections', []) print("Selection indices:", sel_indices) hover_indices = self.index_datasource.metadata.get('hover', []) print("Hover indices:", hover_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
class MieComparePlot(HasTraits): ''' Developed 4_14_12, container object that stores two instances of plots and a creates a third plot to combine both plots. Especially useful for comparing scattering cross section plots for full nanoparticles and composite nanoparticles ''' # Mie1=Instance(ScatterView) #Try making Plot if doesn't work # Mie2=Instance(ScatterView) # plot1=DelegatesTo('Mie1', prefix='sigplot') # plot2=DelegatesTo('Mie1', prefix='sigplot') plot1 = Instance(ToolbarPlot) def _plot1_default(self): return ToolbarPlot() def _plot1_changed(self): print('changed in mie_compare') print(self.plot1) # container = GridContainer(padding=40, fill_padding=True, # bgcolor="lightgray", use_backbuffer=True, # shape=(2,3), spacing=(20,20)) # TotalPlot=Instance(Component) traits_view = View( Item('plot1', show_label=False, editor=ComponentEditor()), ),
class Demo(DemoFrame): canvas = Instance(Component) traits_view = View( Item( "canvas", editor=ComponentEditor(), show_label=False, width=200, height=200, ), resizable=True, ) def _canvas_default(self): image = stars() container = ConstraintsContainer(bounds=[500, 500]) container.add(image) ratio = float(image.data.shape[1]) / image.data.shape[0] container.layout_constraints = [ image.left == container.contents_left, image.right == container.contents_right, image.top == container.contents_top, image.bottom == container.contents_bottom, image.layout_width == ratio * image.layout_height, ] return container
class MyPlot(HasTraits): """ Displays a plot with a few buttons to control which overlay to display """ plot = Instance(Plot) traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False), resizable=True) def __init__(self, x_index, y_index, data, **kw): super(MyPlot, self).__init__(**kw) # Create the data source for the MultiLinePlot. ds = MultiArrayDataSource(data=data) xs = ArrayDataSource(x_index, sort_order='ascending') xrange = DataRange1D() xrange.add(xs) ys = ArrayDataSource(y_index, sort_order='ascending') yrange = DataRange1D() yrange.add(ys) mlp = MultiLinePlot(index=xs, yindex=ys, index_mapper=LinearMapper(range=xrange), value_mapper=LinearMapper(range=yrange), value=ds, global_max=np.nanmax(data), global_min=np.nanmin(data), **kw) self.plot = Plot() self.plot.add(mlp)
class Demo(HasTraits): plot = Instance(Component) controller = Instance(TimerController, ()) timer = Instance(Timer) 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], handler=DemoHandler ) def __init__(self, **traits): super(Demo, self).__init__(**traits) self.cqtkernel = CQTKernel(TOP_MIDINUMBER, BINS, SAMPLING_RATE) self.plot = _create_plot_component(self.controller, self.cqtkernel) def edit_traits(self, *args, **kws): self.timer = Timer(20, self.controller.onTimer) return super(Demo, self).edit_traits(*args, **kws) def configure_traits(self, *args, **kws): self.timer = Timer(20, self.controller.onTimer) return super(Demo, self).configure_traits(*args, **kws)
class ScriptedComponentView(ModelView): """ ModelView of a ScriptedComponent displaying the script and image """ #: the component we are editing model = Instance(ScriptedComponent, ()) view = View( HSplit( VGroup( UItem("model.draw_script"), UItem( "model.error", visible_when="model.error != ''", style="readonly", height=100, ), ), VGroup( UItem("model", editor=ComponentEditor(), springy=True), UItem("model.fps_display", style="readonly"), ), ), resizable=True, title="Kiva Explorer", )
class ExamplePlotApp(HasTraits): plot = Instance(Plot) traits_view = View( Item( 'plot', editor=ComponentEditor(), width=600, height=600, show_label=False), resizable=True) def __init__(self, index, series1, series2, **kw): super(ExamplePlotApp, self).__init__(**kw) plot_data = ArrayPlotData(index=index) plot_data.set_data('series1', series1) plot_data.set_data('series2', series2) self.plot = ToolbarPlot(plot_data) line_plot = self.plot.plot(('index', 'series1'), color='auto')[0] # Add pan and zoom tools line_plot.tools.append(PanTool(line_plot)) line_plot.tools.append(ZoomTool(line_plot)) # Set the domain_limits line_plot.index_mapper.domain_limits = (3.3, 6.6)
def default_traits_view(self): no_endlabel = DefaultOverride(low_label='', high_label='', mode='logslider') no_endlabel_linear = DefaultOverride(low_label='', high_label='', mode='slider') return View(Group(Item('reconstruction', editor=ComponentEditor()), show_labels=False, show_left=False), HGroup(Item('pulses_used', style='readonly'), Item('absolute_sum'), Item('amplitudes_one'), Item('replace'), Item('subtract')), Item('amplitude_threshold_min', editor=no_endlabel, label='Minimum absolute amplitude'), Item('amplitude_threshold_max', editor=no_endlabel), Item('area_threshold_min', editor=no_endlabel), Item('area_threshold_max', editor=no_endlabel), Item('volume_threshold_min', editor=no_endlabel), Item('volume_threshold_max', editor=no_endlabel), Item('circularity_min'), Item('circularity_max'), Item('lifetime_min', editor=no_endlabel_linear), Item('lifetime_max', editor=no_endlabel_linear), Item('output_threshold', editor=no_endlabel_linear), HGroup(Item('save_file', show_label=False), Item('save_button', show_label=False)), width=800, height=600, resizable=True, title='DPT 2D reconstruction')
def default_traits_view(self): view = View( VGroup( self.axis_hgroup, UItem("_component", editor=ComponentEditor()), VGroup(UItem("reset_plot", enabled_when="reset_enabled")), )) return view
def default_traits_view(self): return View( VGroup( Item('plot', editor=ComponentEditor(), show_label=False), ), resizable=True )
def default_traits_view(self): """Implemented to removes the reset_plot option from the parent class View""" view = View( VGroup( self.axis_hgroup, UItem("_component", editor=ComponentEditor()), )) return view
class Demo(HasTraits): canvas = Instance(Component) traits_view = View(Item('canvas', editor=ComponentEditor(bgcolor="lightgray"), show_label=False, width=500, height=500), resizable=True, title="Gradient Example") def _canvas_default(self): return MyCanvas()
def _get_traits_group(self): return VGroup( HGroup( Item('flip_order'), Item('offset'), Item('value_range'), ), UItem('component', editor=ComponentEditor()), )