def __init__(self, signal_instance): super(TemplatePicker, self).__init__() try: import cv except: print "OpenCV unavailable. Can't do cross correlation without it. Aborting." return None self.OK_custom = OK_custom_handler() self.sig = signal_instance if not hasattr(self.sig.mapped_parameters, "original_files"): self.sig.data = np.atleast_3d(self.sig.data) self.titles = [self.sig.mapped_parameters.name] else: self.numfiles = len( self.sig.mapped_parameters.original_files.keys()) self.titles = self.sig.mapped_parameters.original_files.keys() tmp_plot_data = ArrayPlotData( imagedata=self.sig.data[self.top:self.top + self.tmp_size, self.left:self.left + self.tmp_size, self.img_idx]) tmp_plot = Plot(tmp_plot_data, default_origin="top left") tmp_plot.img_plot("imagedata", colormap=jet) tmp_plot.aspect_ratio = 1.0 self.tmp_plot = tmp_plot self.tmp_plotdata = tmp_plot_data self.img_plotdata = ArrayPlotData( imagedata=self.sig.data[:, :, self.img_idx]) self.img_container = self._image_plot_container() self.crop_sig = None
def __init__(self, **traits): super(HistDemo, self).__init__(**traits) img = cv.imread("lena.jpg") gray_img = cv.Mat() cv.cvtColor(img, gray_img, cv.CV_BGR2GRAY) self.img = gray_img self.img2 = self.img.clone() result = cv.MatND() r = cv.vector_float32([0, 256]) ranges = cv.vector_vector_float32([r, r]) cv.calcHist(cv.vector_Mat([self.img]), channels=cv.vector_int([0, 1]), mask=cv.Mat(), hist=result, histSize=cv.vector_int([256]), ranges=ranges) data = ArrayPlotData(x=np.arange(0, len(result[:])), y=result[:]) self.plot = Plot(data, padding=10) line = self.plot.plot(("x", "y"))[0] self.select_tool = RangeSelection(line, left_button_selects=True) line.tools.append(self.select_tool) self.select_tool.on_trait_change(self._selection_changed, "selection") line.overlays.append(RangeSelectionOverlay(component=line)) cv.imshow("Hist Demo", self.img) self.timer = Timer(50, self.on_timer)
def __init__(self): x, y = np.ogrid[-2*np.pi:2*np.pi:256j, -2*np.pi:2*np.pi:256j] self.img_data = np.sin(x)*y #self.img_mask = np.zeros((len(x), len(y[0]), 4), dtype=np.uint8) #self.img_mask[:, :, 3] = 255 self.img_index = np.array(list((np.broadcast(y, x)))) plotdata = ArrayPlotData(img_data=self.img_data, mask_data=self.img_data) plot1 = Plot(plotdata, padding=10) img_plot = plot1.img_plot("img_data", xbounds=(np.min(x), np.max(x)), ybounds=(np.min(y), np.max(y)))[0] self.lasso = LassoSelection(img_plot) img_plot.tools.append(self.lasso) self.ll = LassoOverlay(img_plot, lasso_selection=self.lasso) img_plot.overlays.append(self.ll) self.lasso.on_trait_change(self._selection_changed, 'selection_completed') plot2 = Plot(plotdata, padding=10) plot2.img_plot("mask_data") self.plot = HPlotContainer(plot1, plot2) self.plot1 = plot1 self.plot2 = plot2 self.plotdata = plotdata
def _create_plot_component(): # Create a scalar field to colormap xs = linspace(0, 10, 600) ys = linspace(0, 5, 600) x, y = meshgrid(xs, ys) z = exp(-(x**2 + y**2) / 100) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create the plot plot = Plot(pd) img_plot = plot.img_plot("imagedata", xbounds=(0, 10), ybounds=(0, 5), colormap=jet)[0] # Tweak some of the plot properties plot.title = "My First Image Plot" plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False) img_plot.overlays.append(zoom) return plot
def __init__(self, **traits): super(LassoDemoPlot, self).__init__(**traits) x = np.random.random(N) y = np.random.random(N) x2 = np.array([]) y2 = np.array([]) data = ArrayPlotData(x=x, y=y, x2=x2, y2=y2) plot1 = Plot(data, padding=10) scatter_plot1 = plot1.plot(("x", "y"), type="scatter", marker="circle", color="blue")[0] self.lasso = LassoSelection(scatter_plot1, incremental_select=True, selection_datasource=scatter_plot1.index) self.lasso.on_trait_change(self._selection_changed, 'selection_changed') scatter_plot1.tools.append(self.lasso) scatter_plot1.overlays.append( LassoOverlay(scatter_plot1, lasso_selection=self.lasso)) plot2 = Plot(data, padding=10) plot2.index_range = plot1.index_range plot2.value_range = plot1.value_range plot2.plot(("x2", "y2"), type="scatter", marker="circle", color="red") self.plot = HPlotContainer(plot1, plot2) self.plot2 = plot2 self.data = data
def __init__(self): self.data = ArrayPlotData() self.set_empty_data() self.plot = Plot(self.data, padding=10) scatter = self.plot.plot(("x","y", "c"), type="cmap_scatter", marker_size=1, color_mapper=make_color_map(), line_width=0)[0] self.plot.x_grid.visible = False self.plot.y_grid.visible = False self.plot.x_axis.visible = False self.plot.y_axis.visible = False self.tool = TrianglesTool(self.plot) self.plot.overlays.append(self.tool) try: with file("ifs_chaco.data","rb") as f: tmp = pickle.load(f) self.ifs_names = [x[0] for x in tmp] self.ifs_points = [np.array(x[1]) for x in tmp] if len(self.ifs_names) > 0: self.current_name = self.ifs_names[-1] except: pass self.tool.on_trait_change(self.triangle_changed, 'changed') self.timer = Timer(10, self.ifs_calculate)
def _plot_data_default(self): return ArrayPlotData(rx = (0.0, 1.0), ry = (0.0, 0.0), gx = (0.0, 1.0), gy = (0.0, 0.0), bx = (0.0, 1.0), by = (0.0, 0.0), ax = (0.0, 1.0), ay = (0.0, 0.0), lx = (0.0, 1.0), ly = (0.0, 0.0), ux = (0.0, 1.0), uy = (1.0, 1.0))
def __init__(self): # 首先需要调用父类的初始化函数 super(TriangleWave, self).__init__() # 创建绘图数据集,暂时没有数据因此都赋值为空,只是创建几个名字,以供Plot引用 self.plot_data = ArrayPlotData(x=[], y=[], f=[], p=[], x2=[], y2=[]) # 创建一个垂直排列的绘图容器,它将频谱图和波形图上下排列 self.container = VPlotContainer() # 创建波形图,波形图绘制两条曲线: 原始波形(x,y)和合成波形(x2,y2) self.plot_wave = self._create_plot(("x", "y"), "Triangle Wave") self.plot_wave.plot(("x2", "y2"), color="red") # 创建频谱图,使用数据集中的f和p self.plot_fft = self._create_plot(("f", "p"), "FFT", type="scatter") # 将两个绘图容器添加到垂直容器中 self.container.add(self.plot_wave) self.container.add(self.plot_fft) # 设置 self.plot_wave.x_axis.title = "Samples" self.plot_fft.x_axis.title = "Frequency pins" self.plot_fft.y_axis.title = "(dB)" # 改变fftsize为1024,因为Enum的默认缺省值为枚举列表中的第一个值 self.fftsize = 1024
def __init__(self, **traits): super(ContainerExample, self).__init__(**traits) x = np.linspace(-14, 14, 100) y = np.sin(x) * x**3 / 1000 data = ArrayPlotData(x=x, y=y) p1 = Plot(data, padding=30) p1.plot(("x", "y"), type="scatter", color="blue") p1.plot(("x", "y"), type="line", color="blue") p2 = Plot(data, padding=30) p2.plot(("x", "y"), type="line", color="blue") p2.set(bounds=[200, 100], position=[70, 150], bgcolor=(0.9, 0.9, 0.9), unified_draw=True, resizable="") p3 = Plot(data, padding=30) p3.plot(("x", "y"), type="line", color="blue", line_width=2.0) p4 = Plot(data, padding=30) p4.plot(("x", "y"), type="scatter", color="red", marker="circle") c1 = OverlayPlotContainer(p1, p2) c1.fixed_preferred_size = p3.get_preferred_size() c2 = HPlotContainer(c1, p3) c3 = VPlotContainer(p4, c2) self.plot = c3
def __init__(self, **traits): super(PointSelectionDemo, self).__init__(**traits) x = np.random.rand(100) y = np.random.rand(100) data = ArrayPlotData(x=x, y=y) plot = Plot(data, padding=25) self.scatter = scatter = plot.plot(("x", "y"), type="scatter", marker_size=4)[0] self.select_tools = {} for i, c in enumerate(Colors.keys()): hover_name = "hover_%s" % c selection_name = "selections_%s" % c self.select_tools[c] = ScatterInspector(scatter, hover_metadata_name=hover_name, selection_metadata_name=selection_name) scatter.overlays.append(ScatterInspectorOverlay(scatter, hover_metadata_name = hover_name, selection_metadata_name=selection_name, hover_color = "transparent", hover_outline_color = c, hover_marker_size = 6, hover_line_width = 1, selection_color = Colors[c], )) scatter.active_tool = self.select_tools[self.color] scatter.index.on_trait_change(self.selection_changed, 'metadata_changed') self.plot = plot self.data = data
def _create_plot_component(self): self.data = ArrayPlotData() self.data["frequency"] = np.linspace(0., SAMPLING_RATE/2.0, num=NUM_SAMPLES/2) for i in range(NUM_LINES): self.data['amplitude%d' % i] = np.zeros(NUM_SAMPLES/2) self.data["time"] = np.linspace(0., float(NUM_SAMPLES)/SAMPLING_RATE, num=NUM_SAMPLES) self.data['time_amplitude'] = np.zeros(NUM_SAMPLES) self.data['imagedata'] = np.zeros(( NUM_SAMPLES/2, SPECTROGRAM_LENGTH)) spectrum_plot = Plot(self.data) for i in range(NUM_LINES): if i==NUM_LINES-1: linewidth = 2 color = (1,0,0) else: linewidth = 1 c = (NUM_LINES-i-1)/float(NUM_LINES) color = (1, 0.5+c/2, c) spectrum_plot.plot(("frequency", "amplitude%d" % i), name="Spectrum%d" % i, color=color, line_width=linewidth) spectrum_plot.padding_bottom = 20 spectrum_plot.padding_top = 20 spec_range = list(spectrum_plot.plots.values())[0][0].value_mapper.range spec_range.low = -90 spec_range.high = 0.0 spectrum_plot.index_axis.title = 'Frequency(Hz)' spectrum_plot.value_axis.title = 'Amplitude(dB)' time_plot = Plot(self.data) time_plot.plot(("time", "time_amplitude"), name="Time", color="blue") time_plot.padding_top = 20 time_plot.padding_bottom = 20 time_plot.index_axis.title = 'Time (seconds)' time_plot.value_axis.title = 'Amplitude' time_range = list(time_plot.plots.values())[0][0].value_mapper.range time_range.low = -1.5 time_range.high = 1.5 spectrogram_plot = Plot(self.data) spectrogram_time = (0.0, SPECTROGRAM_LENGTH*NUM_SAMPLES/float(SAMPLING_RATE)) spectrogram_freq = (0.0, SAMPLING_RATE/2.0) spectrogram_plot.img_plot('imagedata', name='Spectrogram', xbounds=spectrogram_time, ybounds=spectrogram_freq, colormap=cm.reverse(cm.Blues), ) range_obj = spectrogram_plot.plots['Spectrogram'][0].value_mapper.range range_obj.high = -20 range_obj.low = -60 spectrogram_plot.padding_bottom = 20 spectrogram_plot.padding_top = 20 container = VPlotContainer() container.add(time_plot) container.add(spectrum_plot) container.add(spectrogram_plot) return container
def load_data(self,X,Y) : self.X = X self.Y = Y plotdata = ArrayPlotData(x = X, y = Y) plot = Plot(plotdata) self.renderer_line = plot.plot(('x','y'),type = 'line', color = "blue")[0] self.renderer_scat = plot.plot(('x','y'),type = 'scatter', color = "blue")[0] self.plot = plot
def __init__(self, **traits): super(AnimationPlot, self).__init__(**traits) data = ArrayPlotData(x=[0], y=[0]) plot = Plot(data) plot.plot(("x", "y"), type="line", color="blue") plot.title = "sin(x)" self.plot = plot self.data = data
def __init__(self): super(ScatterPlotTraits, self).__init__() x = linspace(-14, 14, 100) y = sin(x) * x**3 plotdata = ArrayPlotData(x=x, y=y) plot = Plot(plotdata) self.renderer = plot.plot(("x", "y"), type="scatter", color="blue")[0] self.plot = plot
def __init__(self, **traits): super(MandelbrotDemo, self).__init__(**traits) self.data = ArrayPlotData(image=np.zeros((1, 1))) self.plot = Plot(self.data, padding=0) imgplot = self.plot.img_plot("image", colormap=reverse(Blues), interpolation="bilinear")[0] imgplot.tools.append( MandelbrotController(imgplot, application=self) ) self.imgplot = imgplot self.plot.x_axis.visible = False self.plot.y_axis.visible = False
def _pd_default(self): image = ones(shape=(300, 400)) pd = ArrayPlotData() pd.set_data("imagedata", image) pd.set_data('h_index', numpy.arange(400)) pd.set_data('h_value', numpy.ones((400, ))) pd.set_data('v_index', numpy.arange(300)) pd.set_data('v_value', numpy.ones((300, ))) return pd
def __init__(self): super(LinePlot, self).__init__() x = linspace(-14, 14, 100) y = sin(x) * x**3 plotdata = ArrayPlotData(x=x, y=y) plot = Plot(plotdata) plot.plot(("x", "y"), type="line", color="blue") plot.title = "sin(x) * x^3" self.plot = plot
def init_data(self): file_name = '/home/dpothina/work/apps/pysonde/tests/ysi_test_files/BAYT_20070323_CDT_YS1772AA_000.dat' sonde = Sonde(file_name) sal_ds = np.array([1, 2, 3, 4, 5, 6, 7, 8]) # sonde.data['seawater_salinity'] time_ds = sal_ds**2 # [time.mktime(date.utctimetuple()) for date in sonde.dates] #time_ds = ArrayDataSource(dt) #sal_ds = ArrayDataSource(salinity, sort_order="none") self.plot_data = ArrayPlotData(sal_ds=sal_ds, time_ds=time_ds)
def __init__(self): super(EqualizerDesigner, self).__init__() self.plot_data = ArrayPlotData(f=FREQS, gain=[], phase=[]) self.plot_gain = self._create_plot(("f", "gain"), "Gain(dB)") self.plot_phase = self._create_plot(("f", "phase"), "Phase(degree)") self.container = VPlotContainer() self.container.add(self.plot_phase) self.container.add(self.plot_gain) self.plot_gain.padding_bottom = 20 self.plot_phase.padding_top = 20
def __init__(self, **traits): super(LinePlot, self).__init__(**traits) x = np.linspace(-14, 14, 100) y = np.sin(x) * x**3 data = ArrayPlotData(x=x, y=y) plot = Plot(data) plot.plot(("x", "y"), type="line", color="blue") plot.title = "sin(x) * x^3" self.plot = plot self.data = data
def __init__(self, **traits): super(ScatterPlotTraits, self).__init__(**traits) x = np.linspace(-14, 14, 100) y = np.sin(x) * x**3 data = ArrayPlotData(x=x, y=y) plot = Plot(data) self.line = plot.plot(("x", "y"), type="scatter", color="blue")[0] self.plot = plot self.data = data
def __init__(self): x = numpy.linspace(-14, 14, 100) y = numpy.sin(x) * x**3 plotdata = ArrayPlotData(x=x, y=y) plot = Plot(plotdata) plot.plot(("x", "y"), type="line", color="blue") plot.title = "sin(x) * x^3" self.plot=plot
def __init__(self): super(ImagePlot, self).__init__() x = np.linspace(0, 10, 50) y = np.linspace(0, 5, 50) xgrid, ygrid = np.meshgrid(x, y) z = np.exp(-(xgrid * xgrid + ygrid * ygrid) / 100) plotdata = ArrayPlotData(imagedata=z) plot = Plot(plotdata) plot.img_plot("imagedata", xbounds=x, ybounds=y, colormap=jet) self.plot = plot
def __init__(self): super(ContainerExample, self).__init__() 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) self.plot = container
def __init__(self, dims=(128, 10)): super(ImagePlot, self).__init__() z = numpy.zeros(dims) self.plotdata = ArrayPlotData(imagedata=z) plot = Plot(self.plotdata) plot.img_plot("imagedata", xbounds=(0, dims[1]), ybounds=(0, dims[0]), colormap=self._cmap) self.plot = plot self.flag = True
def __init__(self, options, **kwtraits): super(FiberView, self).__init__(**kwtraits) self.model = FiberModel(options) # debugging self.debug = options.debug self.model.debug = options.debug # timing parameters self.max_packets = options.max_packets self.hertz = options.hertz # extend options to model self.model.max_packets = options.max_packets self.model.preallocate_arrays() self.model.num_analog_channels = options.num_analog_channels # generate traits plot self.plot_data = ArrayPlotData(x=self.model._tdata, y=self.model._ydata) self.plot = Plot(self.plot_data) renderer = self.plot.plot(("x", "y"), type="line", name='old', color="green")[0] # self.plot.delplot('old') # recording flags self.model.recording = False self.model.trialEnded = True print 'Viewer initialized.' # should we wait for a ttl input to start? if options.ttl_start: self.model.ttl_start = True self.ttl_received = False # initialize FIO0 for TTL input self.FIO0_DIR_REGISTER = 6100 self.FIO0_STATE_REGISTER = 6000 self.model.labjack.writeRegister(self.FIO0_DIR_REGISTER, 0) # Set FIO0 low # initialize output array self.out_arr = None # keep track of number of runs self.run_number = 0 self.timer = Timer(self.model.dt, self.time_update) # update every 1 ms
def __init__(self, dims=(128, 10)): super(ImagePlot, self).__init__() #z = numpy.zeros(dims) self.plotdata = ArrayPlotData(neurons=[0], times=[0]) plot = Plot(self.plotdata) plot.plot( ("times", "neurons"), type="scatter", marker="dot", marker_size=1, color='black', ) self.plot = plot
def _create_plot(self): data = ArrayPlotData(t=self.bins, y=self.counts) plot = Plot(data, width=500, height=500, resizable='hv', padding_left=96, padding_bottom=32) plot.plot(('t', 'y'), type='line', color='blue') plot.tools.append(SaveTool(plot)) plot.index_axis.title = 'time [ns]' plot.value_axis.title = 'counts' self.plot_data = data self.plot = plot
def __init__(self): super(IMUGloveDisplay, self).__init__() 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) #scatter.title = "sin(x) * x^3" #line.title = 'line plot' self.plot = container self.InitGlove()
def __init__(self): super(Probe, self).__init__() x = linspace(0, self.N, self.N / self.d) y = linspace(0, self.N, self.N / self.d) xgrid, ygrid = meshgrid(x[1:], y[1:]) z = exp(-(xgrid * xgrid + ygrid * ygrid) / 10000) plotdata = ArrayPlotData(imagedata=z) plot = Plot(plotdata) self.renderer = plot.img_plot("imagedata", xbounds=x, ybounds=y, colormap=bone) #self.renderer = plot.plot(("x", "y"), type="scatter", color="blue")[0] self.plot = plot