def make_plot(self, orientation): # make some data points x = arange(3) x = ArrayDataSource(x, sort_order="ascending") y = array([2, 0, 1]) # Plot the data pd = ArrayPlotData(x=x, y=y) plot = Plot(pd, orientation=orientation) line_plot = plot.plot(("x", "y"))[0] # Construct a fake screen space for the plots # otherwise would need to actually display the plots to get this index_mapper = LinearMapper(data_range=DataRange1D(low=0, high=2), high_pos=380, low_pos=20) value_mapper = LinearMapper(data_range=DataRange1D(low=0, high=2), high_pos=380, low_pos=20) plot.index_mapper = index_mapper plot.value_mapper = value_mapper line_plot.index_mapper = index_mapper line_plot.value_mapper = value_mapper return plot, line_plot
def _signals_data_model_changed(self, old, new): print('model_changed') xs = ArrayDataSource(self.signals_data_model.x_index, sort_order='ascending') xrange = DataRange1D() xrange.add(xs) ys = ArrayDataSource(self.signals_data_model.y_index, sort_order='ascending') yrange = DataRange1D() yrange.add(ys) # The data source for the MultiLinePlot. print('ds') ds = MultiArrayDataSource(data=self.signals_data_model.data) self.signals_renderer.set( index=xs, yindex=ys, #index_mapper = LinearMapper(range=xrange), value_mapper = LinearMapper(range=yrange), value=ds, global_max=self.signals_data_model.data.max(), global_min=self.signals_data_model.data.min()) self.signals_renderer.index_mapper.range = xrange self.signals_renderer.value_mapper.range = yrange self.signals_renderer.request_redraw()
def setUp(self): self.index = ArrayDataSource(arange(10)) self.value = ArrayDataSource(arange(10)) self.color_data = ArrayDataSource(arange(10)) self.size_data = arange(10) self.index_range = DataRange1D() self.index_range.add(self.index) self.index_mapper = LinearMapper(range=self.index_range) self.value_range = DataRange1D() self.value_range.add(self.value) self.value_mapper = LinearMapper(range=self.value_range) self.color_range = DataRange1D() self.color_range.add(self.color_data) self.color_mapper = jet(self.color_range) self.scatterplot = ColormappedScatterPlot( index=self.index, value=self.value, index_mapper=self.index_mapper, value_mapper=self.value_mapper, color_data=self.color_data, marker_size=self.size_data, color_mapper=self.color_mapper, ) self.scatterplot.outer_bounds = [50, 50] self.gc = PlotGraphicsContext((50, 50))
def _create_plot_component(): # Create some data numpts = 400 x = sort(random(numpts)) y = random(numpts) xs = ArrayDataSource(x, sort_order='ascending') ys = ArrayDataSource(y) vectorlen = 15 vectors = array((random(numpts) * vectorlen, random(numpts) * vectorlen)).T vector_ds = MultiArrayDataSource(vectors) xrange = DataRange1D() xrange.add(xs) yrange = DataRange1D() yrange.add(ys) quiverplot = QuiverPlot(index=xs, value=ys, vectors=vector_ds, index_mapper=LinearMapper(range=xrange), value_mapper=LinearMapper(range=yrange), bgcolor="white") add_default_axes(quiverplot) add_default_grids(quiverplot) # Attach some tools to the plot quiverplot.tools.append(PanTool(quiverplot, constrain_key="shift")) zoom = ZoomTool(quiverplot) quiverplot.overlays.append(zoom) container = OverlayPlotContainer(quiverplot, padding=50) return container
def _update_rangeselect(self): ''' Overwrites range selection tool in current plot.''' #### Remove current overlay self.plot.overlays = [ obj for obj in self.plot.overlays if not isinstance(obj, RangeSelectionOverlay) ] mycomp = self.plot.plots.itervalues().next()[ 0] #Quick wayt to get first value in dictionary inds = range(len(self.df.index)) idx = ArrayDataSource(inds) vals = ArrayDataSource(df.index.values) index_range = DataRange1D(idx) val_range = DataRange1D(vals) imap = LinearMapper( range=index_range) #,stretch_data=self.index_mapper.stretch_data) vmap = LinearMapper(range=val_range) # mycomp.index_range.refresh() mycomp.index_mapper = imap mycomp.value_mapper = vmap self.rangeselect = RangeSelection(mycomp, axis=self.selection_axis) self.plot.active_tool = self.rangeselect self.plot.overlays.append(RangeSelectionOverlay(component=mycomp)) self.rangeselect.on_trait_change(self.on_selection_changed, "selection")
def _bar_plot_default(self): # Default data idx = np.array([1, 2, 3, 4, 5]) vals = np.array([2, 4, 7, 4, 3]) # Mappers index = ArrayDataSource(idx) index_range = DataRange1D(index, low=0.5, high=5.5) index_mapper = LinearMapper(range=index_range) value = ArrayDataSource(vals) value_range = DataRange1D(value, low=0) value_mapper = LinearMapper(range=value_range) # The bar plot plot = BarPlot( index=index, value=value, value_mapper=value_mapper, index_mapper=index_mapper, line_color="black", fill_color="cornflowerblue", bgcolor="white", bar_width=self.bar_width, line_width=self.line_width, ) return plot
def create_multi_line_plot_renderer(x_index, y_index, data, amplitude=0.5): # 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), #use_global_bounds=True, #default_origin='top left', origin='top left', #**kw ) mlp.normalized_amplitude = amplitude return mlp
def _multi_line_plot_renderer_default(self): """Create the default MultiLinePlot instance.""" xs = ArrayDataSource(self.model.x_index, sort_order='ascending') xrange = DataRange1D() xrange.add(xs) ys = ArrayDataSource(self.model.y_index, sort_order='ascending') yrange = DataRange1D() yrange.add(ys) # The data source for the MultiLinePlot. ds = MultiArrayDataSource(data=self.model.data) multi_line_plot_renderer = \ MultiLinePlot( index = xs, yindex = ys, index_mapper = LinearMapper(range=xrange), value_mapper = LinearMapper(range=yrange), value=ds, global_max = self.model.data.max(), global_min = self.model.data.min()) return multi_line_plot_renderer
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)
def _create_price_plots(self, times, prices, mini_height=75): """ Creates the two plots of prices and returns them. One of the plots can be zoomed and panned, and the other plot (smaller) always shows the full data. *dates* and *prices* are two data sources. """ # Create the price plot price_plot = FilledLinePlot( index=times, value=prices, index_mapper=LinearMapper(range=DataRange1D(times)), value_mapper=LinearMapper(range=DataRange1D(prices)), edge_color="blue", face_color="paleturquoise", bgcolor="white", border_visible=True) # Add pan and zoom price_plot.tools.append( PanTool( price_plot, constrain=True, constrain_direction="x")) price_plot.overlays.append( ZoomTool( price_plot, drag_button="right", always_on=True, tool_mode="range", axis="index", max_zoom_out_factor=1.0, )) # Create the miniplot miniplot = LinePlot( index=times, value=prices, index_mapper=LinearMapper(range=DataRange1D(times)), value_mapper=LinearMapper(range=DataRange1D(prices)), color="black", border_visible=True, bgcolor="white", height=mini_height, resizable="h") # Add a range overlay to the miniplot that is hooked up to the range # of the main price_plot range_tool = RangeSelection(miniplot) miniplot.tools.append(range_tool) range_overlay = RangeSelectionOverlay( miniplot, metadata_name="selections") miniplot.overlays.append(range_overlay) range_tool.on_trait_change(self._range_selection_handler, "selection") # Attach a handler that sets the tool when the plot's index range changes self.range_tool = range_tool price_plot.index_range.on_trait_change(self._plot_range_handler, "updated") return price_plot, miniplot
def __init__(self, velocity_callback=None, x_range=DataRange1D(low=0, high=size[0]), y_range=DataRange1D(low=0, high=size[1]), *args, **kwargs): super().__init__(*args, **kwargs) self.robot_bounding_box = { "x": [100, 200, 200, 100], "y": [80, 80, 220, 220] } self.robot_wheels = [ { # Bottom-left "x": [90, 110, 110, 90], "y": [90, 90, 140, 140] }, { # Bottom-right "x": [190, 210, 210, 190], "y": [90, 90, 140, 140] }, { # Top-right "x": [90, 110, 110, 90], "y": [160, 160, 210, 210] }, { # Top-left "x": [190, 210, 210, 190], "y": [160, 160, 210, 210] }, ] self.plot_data = ArrayPlotData(robot_x=self.robot_bounding_box['x'], robot_y=self.robot_bounding_box['y'], wheel_bl_x=self.robot_wheels[0]['x'], wheel_bl_y=self.robot_wheels[0]['y'], wheel_br_x=self.robot_wheels[1]['x'], wheel_br_y=self.robot_wheels[1]['y'], wheel_tr_x=self.robot_wheels[2]['x'], wheel_tr_y=self.robot_wheels[2]['y'], wheel_tl_x=self.robot_wheels[3]['x'], wheel_tl_y=self.robot_wheels[3]['y'], arrow_x=[0, 100, 200], arrow_y=[0, 100, 100], arrowhead_x=[150, 200], arrowhead_y=[150, 200]) self.x_range = x_range self.y_range = y_range self.velocity_callback = velocity_callback velocity_tool = VelocityTool((150, 150), (300, 300), self.update_velocity, self.hover_velocity) # Show starting plot self.plot = self.plot_robot() self.plot.tools.append(velocity_tool) self.plot_velocity()
def test_range_data_range_changed(self): self.data_source.data_range = DataRange1D(low_setting=0.0, high_setting=1.0) with self.assertTraitChanges(self.data_source, 'data_changed', count=1): self.data_source.data_range = DataRange1D(low_setting=-2.0, high_setting=2.0) assert_array_equal( linspace(-2.0, 2.0, 101)**2, self.data_source.get_data())
def gen_line_plot(series_one, series_two, y_axis_name=''): """ Parameters ---------- series_one : nd array series_two : nd array """ size = min(series_one.shape[0], series_two.shape[0]) idx = ArrayDataSource(arange(size)) series_one_data = ArrayDataSource(series_one[:size]) series_two_data = ArrayDataSource(series_two[:size]) y_range = DataRange1D(series_one_data) y_range.tight_bounds = False y_range.margin = 50 x_mapper = LinearMapper(range=DataRange1D(idx)) y_mapper = LinearMapper(range=y_range) series_one_plot = LinePlot(index=idx, value=series_one_data, index_mapper=x_mapper, value_mapper=y_mapper, color='blue') series_two_plot = LinePlot(index=idx, value=series_two_data, index_mapper=x_mapper, value_mapper=y_mapper, color='red') container = OverlayPlotContainer(bgcolor='white', padding=25, fill_padding=False, border_visible=True) y_axis = PlotAxis(mapper=y_mapper, component=container, orientation='left') x_axis = PlotAxis(mapper=x_mapper, component=container, orientation='bottom') x_axis.title = 'Time' y_axis.title = y_axis_name legend = Legend(component=container, padding=10, align='ur') legend.plots = { 'Predicted': series_one_plot, 'Actual': series_two_plot, } container.add(series_one_plot) container.add(series_two_plot) container.overlays.append(y_axis) container.overlays.append(legend) return container
def _make_curves(self): (index_points, value_points) = self._get_points() size = len(index_points) middle_value = 2500000.0 mid_values = middle_value * ones(size) low_values = mid_values - 10000.0 * value_points high_values = mid_values + 20000.0 * value_points idx = ArrayDataSource(index_points) vals = ArrayDataSource(low_values, sort_order="none") idx2 = ArrayDataSource(index_points) vals2 = ArrayDataSource(high_values, sort_order="none") starting_vals = ArrayDataSource(mid_values, sort_order="none") # Create the index range index_range = DataRange1D(idx, low=0.5, high=9.5) index_mapper = LinearMapper(range=index_range) # Create the value range value_range = DataRange1D(vals, vals2, low_setting='auto', high_setting='auto', tight_bounds=False) value_mapper = LinearMapper(range=value_range, tight_bounds=False) # Create the plot plot1 = BarPlot(index=idx, value=vals, value_mapper=value_mapper, index_mapper=index_mapper, starting_value=starting_vals, line_color='black', orientation='v', fill_color=tuple(COLOR_PALETTE[6]), bar_width=0.8, antialias=False) plot2 = BarPlot(index=idx2, value=vals2, value_mapper=value_mapper, index_mapper=index_mapper, starting_value=starting_vals, line_color='black', orientation='v', fill_color=tuple(COLOR_PALETTE[1]), bar_width=0.8, antialias=False) return [plot1, plot2]
def _signals_renderer_default(self): print('_signals_renderer_default') """Create the default MultiLinePlot instance.""" xs = ArrayDataSource(self.signals_data_model.x_index, sort_order='ascending') xrange = DataRange1D() xrange.add(xs) ys = ArrayDataSource(self.signals_data_model.y_index, sort_order='ascending') yrange = DataRange1D() yrange.add(ys) # The data source for the MultiLinePlot. ds = MultiArrayDataSource(data=self.signals_data_model.data) multi_line_plot_renderer = \ MultiLinePlot( index = xs, yindex = ys, index_mapper = LinearMapper(range=xrange), value_mapper = LinearMapper(range=yrange), value=ds, global_max = self.signals_data_model.data.max(), global_min = self.signals_data_model.data.min(), fast_clip = False) # Add pan tool multi_line_plot_renderer.tools.append( PanTool(multi_line_plot_renderer, restrict_to_data=True)) # Add zoom tool multi_line_plot_renderer.overlays.append( ZoomTool(multi_line_plot_renderer, tool_mode="range", always_on=False, x_max_zoom_factor=20.0, y_max_zoom_factor=20.0, x_min_zoom_factor=1.0, y_min_zoom_factor=1.0, zoom_to_mouse=True)) #multi_line_plot_renderer.overlays.append(LineInspector(multi_line_plot_renderer, axis="index",write_metadata=True,is_listener=True)) # multi_line_plot_renderer.overlays.append(LineInspector(multi_line_plot_renderer, axis='value', # write_metadata=True, # is_listener=True)) multi_line_plot_renderer.overlays.append( LineInspector(multi_line_plot_renderer, axis="index", write_metadata=True, is_listener=True)) return multi_line_plot_renderer
def test_clip_data(self): r = DataRange1D(low=2.0, high=10.0) ary = array([1, 3, 4, 9.8, 10.2, 12]) assert_equal(r.clip_data(ary), array([3.0, 4.0, 9.8])) r = DataRange1D(low=10, high=20) ary = array([5, 10, 15, 20, 25, 30]) assert_equal(r.clip_data(ary), array([10, 15, 20])) assert_equal(r.clip_data(ary[::-1]), array([20, 15, 10])) r = DataRange1D(low=2.0, high=2.5) assert_equal(len(r.clip_data(ary)), 0) return
def __init__(self, link): super(TrackingView, self).__init__() self.link = link self.link.add_callback(MSG_TRACKING_SNRS, self.tracking_snrs_callback) # ======= Line Plot ======= self.plot_data = ArrayPlotData(t=[0.0]) self.plot = Plot(self.plot_data, auto_colors=colours_list) self.plot.value_range.tight_bounds = False self.plot.value_range.low_setting = 0.0 for n in range(TRACK_N_CHANNELS): self.plot_data.set_data('ch'+str(n), [0.0]) self.plot.plot(('t', 'ch'+str(n)), type='line', color='auto') # ======= Bar Plot ======= idxs = ArrayDataSource(range(1, len(self.snrs)+1)) self.vals = ArrayDataSource(self.snrs, sort_order='none') # Create the index range index_range = DataRange1D(idxs, low=0.4, high=TRACK_N_CHANNELS+0.6) index_mapper = LinearMapper(range=index_range) # Create the value range value_range = DataRange1D(low=0.0, high=25.0) value_mapper = LinearMapper(range=value_range) plot = BarPlot(index=idxs, value=self.vals, index_mapper=index_mapper, value_mapper=value_mapper, line_color='blue', fill_color='blue', bar_width=0.8) container = OverlayPlotContainer(bgcolor = "white") plot.padding = 10 plot.padding_left = 30 plot.padding_bottom = 30 container.add(plot) left_axis = PlotAxis(plot, orientation='left') bottom_axis = LabelAxis(plot, orientation='bottom', labels = map(str, range(1, TRACK_N_CHANNELS+1)), positions = range(1, TRACK_N_CHANNELS+1), small_haxis_style=True) plot.underlays.append(left_axis) plot.underlays.append(bottom_axis) self.snr_bars = container self.python_console_cmds = { 'track': self }
def _refresh_container(self): ''' rebuild the container for the current data ''' broadcaster = BroadcasterTool() mfn_line = self.value # print self.panel.GetSize() adapter = self.adapter if adapter.var_x != '': # Get the x-label text from the object's trait var_x label_x = getattr(self.object, adapter.var_x) else: # Get the x-label from the adapter label_x = adapter.label_x if adapter.var_y != '': label_y = getattr(self.object, adapter.var_y) else: label_y = adapter.label_y index = ArrayDataSource(mfn_line.xdata) y = ArrayDataSource(mfn_line.ydata, sort_order="none") index_range = DataRange1D() index_range.add(index) index_mapper = LinearMapper(range=index_range) value_range = DataRange1D(low_setting=0.0) value_range.add(y) value_mapper = LinearMapper(range=value_range) styles_m = list(adapter.line_style.values()) line_style = styles_m[0] line_color = adapter.line_color[0] line_plot = self.lplot = LinePlot(index=index, value=y, index_mapper=index_mapper, value_mapper=value_mapper, color=line_color, width=25, edge_color='blue', linestyle=line_style, border_visible=False) add_default_grids(line_plot) add_default_axes(line_plot, vtitle="Y", htitle="X") self.plot_container.add(line_plot) line_plot.tools.append(PanTool(line_plot)) line_plot.overlays.append(ZoomTool(line_plot))
def test_mask_data(self): r = DataRange1D(low=2.0, high=10.0) ary = array([1, 3, 4, 9.8, 10.2, 12]) assert_equal(r.mask_data(ary), array([0, 1, 1, 1, 0, 0], 'b')) r = DataRange1D(low=10, high=20) ary = array([5, 10, 15, 20, 25, 30]) target_mask = array([0, 1, 1, 1, 0, 0], 'b') assert_equal(r.mask_data(ary), target_mask) assert_equal(r.mask_data(ary[::-1]), target_mask[::-1]) r = DataRange1D(low=2.0, high=2.5) assert_equal(r.mask_data(ary), zeros(len(ary))) return
def test_multi_source(self): ds1 = ArrayDataSource(array([3, 4, 5, 6, 7])) ds2 = ArrayDataSource(array([5, 10, 15, 20])) r = DataRange1D(ds1, ds2) self.assertEqual(r.low, 3.0) self.assertEqual(r.high, 20.0) return
def test_constant_value(self): r = DataRange1D() ary = array([3.14]) ds = ArrayDataSource(ary) r.add(ds) # A constant value > 1.0, by default, gets a range that brackets # it to the nearest power of ten above and below self.assertEqual(r.low, 1.0) self.assertEqual(r.high, 10.0) r.remove(ds) ds = ArrayDataSource(array([31.4])) r.add(ds) self.assertEqual(r.low, 10.0) self.assertEqual(r.high, 100.0) r.remove(ds) ds = ArrayDataSource(array([0.125])) r.add(ds) self.assertEqual(r.low, 0.0) self.assertEqual(r.high, 0.25) r.remove(ds) ds = ArrayDataSource(array([-0.125])) r.add(ds) self.assertEqual(r.low, -0.25) self.assertEqual(r.high, 0.0) return
def test_single_source(self): r = DataRange1D() ary = arange(10.0) ds = ArrayDataSource(ary) r.sources.append(ds) self.assertEqual(r.low, 0.0) self.assertEqual(r.high, 9.0) r.low = 3.0 r.high = 6.0 self.assertEqual(r.low_setting, 3.0) self.assertEqual(r.high_setting, 6.0) self.assertEqual(r.low, 3.0) self.assertEqual(r.high, 6.0) r.refresh() self.assertEqual(r.low_setting, 3.0) self.assertEqual(r.high_setting, 6.0) self.assertEqual(r.low, 3.0) self.assertEqual(r.high, 6.0) r.low = "auto" self.assertEqual(r.low_setting, "auto") self.assertEqual(r.low, 0.0) return
def test_default_colormaps_smoke(self): # Runs some data through each of the default colormaps and do basic # sanity checks. x = np.linspace(-1.5, 2.0, 8) datarange = DataRange1D(low_setting=-1.0, high_setting=1.5) for cmap_func in default_colormaps.color_map_functions: cmapper = cmap_func(datarange) rgba = cmapper.map_screen(x) self.assertEqual(rgba.shape, (8, 4)) self.assertTrue(np.isfinite(rgba).all()) self.assertTrue((rgba >= 0.0).all()) self.assertTrue((rgba <= 1.0).all()) # No transparency for any of the defaults. assert_array_equal(rgba[:, -1], np.ones(8)) assert_array_equal(rgba[0], rgba[1]) assert_array_equal(rgba[-2], rgba[-1]) r_cmapper = default_colormaps.reverse(cmap_func)(datarange) r_rgba = r_cmapper.map_screen(x) assert_array_equal(r_rgba, rgba[::-1]) c_cmapper = default_colormaps.center(cmap_func)(datarange) self.assertEqual(c_cmapper.range.low, -1.5) self.assertEqual(c_cmapper.range.high, 1.5) f_cmapper = default_colormaps.fix(cmap_func, (0.0, 1.0))(datarange) self.assertEqual(f_cmapper.range.low, 0.0) self.assertEqual(f_cmapper.range.high, 1.0)
def test_get_data_mask(self): self.data_source.data_range = DataRange1D(low_setting=0.0, high_setting=1.0) data, mask = self.data_source.get_data_mask() assert_array_equal(data, linspace(0.0, 1.0, 101)**2) assert_array_equal(mask, ones(shape=101, dtype=bool))
def _update_images(self): """ Updates the image data in self.plotdata to correspond to the slices given. """ range = DataRange1D(low=self.model.minval, high=self.model.maxval) self.colormap = self.cmap(range) slicexy=self.model.vals[:, :, self.slice_z] colorslicexy=(self.colormap.map_screen(slicexy) * 255).astype(uint8) # Transposed required because img_plot() expects data in row-major order self.plotdata.set_data("xy", transpose(colorslicexy,(1,0,2))) slicexz=self.model.vals[:, self.slice_y, :] colorslicexz=(self.colormap.map_screen(slicexz) * 255).astype(uint8) # Transposed required because img_plot() expects data in row-major order self.plotdata.set_data("xz", transpose(colorslicexz,(1,0,2))) sliceyz=self.model.vals[self.slice_x, :, :] colorsliceyz=(self.colormap.map_screen(sliceyz) * 255).astype(uint8) #print "colorsliceyz.shape=",colorsliceyz.shape #print "type(colorsliceyz)=",type(colorsliceyz) #print "type(colorsliceyz[0,0,0])=",type(colorsliceyz[0,0,0]) self.plotdata.set_data("yz", colorsliceyz)
def test_basic(self): ary = array([1.0, 10.0, 100.0, 1000.0, 10000.0]) ds = ArrayDataSource(ary) r = DataRange1D(ds) mapper = LogMapper(range=r, low_pos=50, high_pos=90) result = mapper.map_screen(ary) assert_equal(result, array([50, 60, 70, 80, 90]))
def test_negative(self): ary = array([1.0, -1.0, -2.0, 10.0, 100.0, 1000.0]) ds = ArrayDataSource(ary) r = DataRange1D(ds) mapper = LogMapper(range=r, low_pos=0, high_pos=30) result = mapper.map_screen(ary) assert_array_almost_equal(result, [0, 0, 0, 10, 20, 30])
def test_scatter_1d_set_index_mapper_notifies_index_range(self): new_range = DataRange1D(low=0.42, high=1.42) with self.assertTraitChanges(self.scatterplot, "index_range", count=1): self.scatterplot.index_mapper = LinearMapper(range=new_range) self.assertIs(self.scatterplot.index_range, new_range)
def test_fractional(self): ary = array([0.0001, 0.001, 0.01]) ds = ArrayDataSource(ary) r = DataRange1D(ds) mapper = LogMapper(range=r, low_pos=0, high_pos=20) result = mapper.map_screen(ary) assert_array_almost_equal(result, [0, 10, 20])
def test_redraw_on_color_mapper_update(self): # regression check for https://github.com/enthought/chaco/issues/220 npoints = 200 xs = numpy.linspace(-2 * numpy.pi, +2 * numpy.pi, npoints) ys = numpy.linspace(-1.5 * numpy.pi, +1.5 * numpy.pi, npoints) x, y = numpy.meshgrid(xs, ys) z = y * x index = GridDataSource(xdata=xs, ydata=ys) index_mapper = GridMapper(range=DataRange2D(index)) color_source = ImageData(data=z, value_depth=1) color_mapper = Spectral(DataRange1D(color_source)) cmap_plot = CMapImagePlot( index=index, index_mapper=index_mapper, value=color_source, value_mapper=color_mapper, ) cmap_plot._window = window = mock.Mock(spec=AbstractWindow) #when cmap_plot.color_mapper.updated = True # Then window.redraw.assert_called_once_with()