def test(): sample_path = os.path.join('examples', 'data', 'sample.wav') alt_path = os.path.join('..', 'data', 'sample.wav') fname = find_resource( 'Chaco', sample_path, alt_path=alt_path, return_path=True) index, data = wav_to_numeric(fname) print(data[:100]) return index, data
def test(): sample_path = os.path.join('examples','data','sample.wav') alt_path = os.path.join('..','data','sample.wav') fname = find_resource('Chaco', sample_path, alt_path=alt_path, return_path=True) index, data = wav_to_numeric(fname) print data[:100] return index, data
# Enthought imports from enable.api import Component, ComponentEditor from traits.api import HasTraits, Instance from traitsui.api import Item, Group, View from traits.util.resource import find_resource # Chaco imports from chaco.api import VPlotContainer, ArrayPlotData, Plot, PlotGrid, PlotAxis from chaco.tools.api import RangeSelection # Relative imports from zoom_overlay import ZoomOverlay sample_path = os.path.join('examples','data','sample.wav') alt_path = os.path.join('..','data','sample.wav') fname = find_resource('Chaco', sample_path, alt_path=alt_path, return_path=True) numpts = 3000 def read_music_data(): from wav_to_numeric import wav_to_numeric index, data = wav_to_numeric(fname) return index[:numpts], data[:numpts] class ZoomPlot(HasTraits): '''Encapsulation of the zoom plot concept. This class organzies the data, plot container and ZoomOverlay required for a zoom plot. ZoomPlot represents the first step towards a reusable and extensible generalization of the zoom plot.
# Python lists. type_manager.register_type_adapters( ContextAdapterFactory( adaptee_class=list, adapter_class=ListContextAdapter, ), list) # Python objects. type_manager.register_type_adapters(InstanceContextAdapterFactory(), object) # Get the path to the data directory data_path = os.path.join('examples', 'naming', 'data') full_path = find_resource('AppTools', data_path, alt_path='data', return_path=True) # Create the root context. root = PyFSContext(path=full_path) root.environment[Context.TYPE_MANAGER] = type_manager # Create and open the main window. window = Explorer(root=Binding(name='Root', obj=root)) window.open() # Start the GUI event loop. gui.start_event_loop() ##### EOF #####################################################################
from enable.api import Component, ComponentEditor from traits.api import HasTraits, Instance from traitsui.api import Item, Group, View from traits.util.resource import find_resource # Chaco imports from chaco.api import VPlotContainer, ArrayPlotData, Plot, PlotGrid, PlotAxis from chaco.tools.api import RangeSelection # Relative imports from .zoom_overlay import ZoomOverlay sample_path = os.path.join('examples', 'data', 'sample.wav') alt_path = os.path.join('..', 'data', 'sample.wav') fname = find_resource('Chaco', sample_path, alt_path=alt_path, return_path=True) numpts = 3000 def read_music_data(): from .wav_to_numeric import wav_to_numeric index, data = wav_to_numeric(fname) return index[:numpts], data[:numpts] class ZoomPlot(HasTraits): '''Encapsulation of the zoom plot concept. This class organzies the data, plot container and ZoomOverlay required for a zoom plot. ZoomPlot represents the first step towards a reusable and
class DemoView(HasTraits): ### Public Traits ########################################################## # A Plot Data object to hold our image data pd = Instance(ArrayPlotData, ()) # A Plot object to plot our image data plot = Instance(Plot) ### Private Traits ######################################################### # File name to load image from resource_path = os.path.join('examples', 'basic', 'capitol.jpg') alt_path = 'capitol.jpg' image_path = find_resource('Chaco', resource_path, alt_path=alt_path, return_path=True) _load_file = File(image_path) # File name to save image to _save_file = File ### Traits Views ########################################################### # This view is for a file dialog to select the 'load' filename load_file_view = View( Item('_load_file'), buttons=OKCancelButtons, kind='livemodal', # NB must use livemodal, plot objects don't copy well width=400, resizable=True, ) # This view is for a file dialog to select the 'save' filename save_file_view = View( Item('_save_file'), buttons=OKCancelButtons, kind='livemodal', # NB must use livemodal, plot objects don't copy well width=400, resizable=True, ) #--------------------------------------------------------------------------- # Public 'DemoView' interface #--------------------------------------------------------------------------- def __init__(self, *args, **kwargs): super(DemoView, self).__init__(*args, **kwargs) # Create the plot object, set some options, and add some tools plot = self.plot = Plot(self.pd, default_origin="top left") plot.x_axis.orientation = "top" plot.padding = 50 plot.padding_top = 75 plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # Load the default image self._load() # Plot the image plot with this image self.plot.img_plot("imagedata") def default_traits_view(self): """ Returns the default view to use for this class. """ # NOTE: I moved the view to this method so we can declare a handler # for the view. Alternatively, we could move the DemoController class # to the top and declare view=Instance(HasTraits) instead. traits_view = View( Item( 'plot', editor=ComponentEditor(), show_label=False, ), menubar=MenuBar( Menu( Action(name="Save Plot", action="save"), # see Controller for Action(name="Load Plot", action="load"), # these callbacks Separator(), CloseAction, name="File", ), ), width=600, height=600, resizable=True, handler=DemoController) return traits_view #--------------------------------------------------------------------------- # Private 'DemoView' interface #--------------------------------------------------------------------------- def _save(self): # Create a graphics context of the right size win_size = self.plot.outer_bounds plot_gc = PlotGraphicsContext(win_size) # Have the plot component into it plot_gc.render_component(self.plot) # Save out to the user supplied filename plot_gc.save(self._save_file) def _load(self): try: # Load the image with the user supplied filename image = ImageData.fromfile(self._load_file) # Update the plot data. NB we must extract _date from the image # for the time being, until ImageData is made more friendly self.pd.set_data("imagedata", image._data) # Set the title and redraw self.plot.title = os.path.basename(self._load_file) self.plot.request_redraw() except: # If loading fails, simply do nothing pass
# Standard library imports import os.path import sys # Enthought library imports from traits.util.resource import find_resource from chaco.shell import imread, imshow, title, show # Get the image file using the find_resource module image_path = os.path.join('examples', 'basic', 'capitol.jpg') alt_path = os.path.join('..', 'basic', 'capitol.jpg') image_file = find_resource('Chaco', image_path, alt_path=alt_path) # Check to see if the image was found if image_file is None: print('The image "capitol.jpg" could not be found.') sys.exit() # Create the image image = imread(image_file) # Create the plot imshow(image, origin="top left") # Alternatively, you can call imshow using the path to the image file #imshow(alt_path) # Add a title title("Simple Image Plot") # This command is only necessary if running from command line
type_manager.register_type_adapters( ContextAdapterFactory( adaptee_class=list, adapter_class=ListContextAdapter, ), list ) # Python objects. type_manager.register_type_adapters( InstanceContextAdapterFactory(), object ) # Get the path to the data directory data_path = os.path.join('examples','naming','data') full_path = find_resource('AppTools', data_path, alt_path='data', return_path=True) # Create the root context. root = PyFSContext(path=full_path) root.environment[Context.TYPE_MANAGER] = type_manager # Create and open the main window. window = Explorer(root=Binding(name='Root', obj=root)) window.open() # Start the GUI event loop. gui.start_event_loop() ##### EOF #####################################################################
# Standard library imports import os.path import sys # Enthought library imports from traits.util.resource import find_resource from chaco.shell import imread, imshow, title, show # Get the image file using the find_resource module image_path = os.path.join('examples','basic','capitol.jpg') alt_path = os.path.join('..','basic','capitol.jpg') image_file = find_resource('Chaco', image_path, alt_path=alt_path) # Check to see if the image was found if image_file is None: print('The image "capitol.jpg" could not be found.') sys.exit() # Create the image image = imread(image_file) # Create the plot imshow(image, origin="top left") # Alternatively, you can call imshow using the path to the image file #imshow(alt_path) # Add a title title("Simple Image Plot") # This command is only necessary if running from command line
def __init__(self, *args, **kwargs): super(Demo, self).__init__(*args, **kwargs) from imread import imread imarray = imread(find_resource('imageAlignment', '../images/GIRLS-IN-SPACE.jpg', '../images/GIRLS-IN-SPACE.jpg', return_path=True)) self.pd = ArrayPlotData(imagedata=imarray) #self.pd.x_axis.orientation = "top" self.plot = HPlotContainer() titles = ["I KEEP DANCE", "ING ON MY OWN"] self._load() i = 0 for plc in [Plot, Plot]: xs = linspace(0, 334*pi, 333) ys = linspace(0, 334*pi, 333) x, y = meshgrid(xs,ys) z = tanh(x*y/6)*cosh(exp(-y**2)*x/3) z = x*y _pd = ArrayPlotData() _pd.set_data("drawdata", z) _pd.set_data("imagedata", self.pd.get_data('imagedata')) plc = Plot(_pd, title="render_style = hold", padding=50, border_visible=True, overlay_border=True) self.plot.add(plc) plc.img_plot("imagedata", alpha=0.95) # Create a contour polygon plot of the data plc.contour_plot("drawdata", type="poly", poly_cmap=jet, xbounds=(0, 499), ybounds=(0, 582), alpha=0.35) # Create a contour line plot for the data, too plc.contour_plot("drawdata", type="line", xbounds=(0, 499), ybounds=(0, 582), alpha=0.35) # Create a plot data obect and give it this data plc.legend.visible = True plc.title = titles[i] i += 1 #plc.plot(("index", "y0"), name="j_0", color="red", render_style="hold") #plc.padding = 50 #plc.padding_top = 75 plc.tools.append(PanTool(plc)) zoom = ZoomTool(component=plc, tool_mode="box", always_on=False) plc.overlays.append(zoom) # Tweak some of the plot properties plc.padding = 50 #zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False) #plot1.overlays.append(zoom) # Attach some tools to the plot #attach_tools(plc) plc.bg_color = None plc.fill_padding = True