def test_clip_data(self): r = DataRange2D(low=[2.0,5.0], high=[10.0,8.0]) x= arange(10.0) y= arange(0.,20.,2.) ary= transpose(array([x,y])) assert_equal(r.clip_data(ary) , array([[3.,6.],[4.,8.]])) r = DataRange2D(low=[10.,10.], high=[20.,20.]) x= arange(10.0,30.,2.) y= arange(0.,40.,4.) ary = transpose(array([x,y])) assert_equal(r.clip_data(ary) , array([[16.,12.],[18.,16.],[20.,20.]])) assert_equal(r.clip_data(ary[::-1]) , array([[20,20], [18,16], [16,12]])) return
def test_constant_values(self): r = DataRange2D() ds = PointDataSource(array([[5.0, 5.0]]), sort_order="none") 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 assert_ary_(r.low, array([1.0, 1.0])) assert_ary_(r.high, array([10.0, 10.0])) r.remove(ds) ds = PointDataSource(array([[31.4, 9.7]])) r.add(ds) assert_ary_(r.low, array([10.0, 1.0])) assert_ary_(r.high, array([100.0, 10.0])) r.remove(ds) ds = PointDataSource(array([[0.125, 0.125]])) r.add(ds) assert_ary_(r.low, array([0.0, 0.0])) assert_ary_(r.high, array([0.25, 0.25])) r.remove(ds) ds = PointDataSource(array([[-0.125, -0.125]])) r.add(ds) assert_ary_(r.low, array([-0.25, -0.25])) assert_ary_(r.high, array([0.0, 0.0])) return
def test_grid_source(self): test_xd1 = array([1, 2, 3]) test_yd1 = array([1.5, 0.5, -0.5, -1.5]) test_sort_order1 = ('ascending', 'descending') test_xd2 = array([0, 50, 100]) test_yd2 = array([0.5, 0.75, 1]) ds1 = GridDataSource(xdata=test_xd1, ydata=test_yd1, sort_order=test_sort_order1) ds2 = GridDataSource(xdata=test_xd2, ydata=test_yd2) r = DataRange2D() r.add(ds1) assert_ary_(r.low, array([1, -1.5])) assert_ary_(r.high, array([3, 1.5])) r.add(ds2) assert_ary_(r.low, array([0.0, -1.5])) assert_ary_(r.high, array([100, 1.5])) r.remove(ds1) assert_ary_(r.low, array([0, 0.5])) assert_ary_(r.high, array([100, 1])) r.remove(ds2) assert_ary_(r.low, array([-inf, -inf])) assert_ary_(r.high, array([inf, inf]))
def test_set_bounds(self): test_xd = array([-10, 10]) test_yd = array([-10, 10]) ds = GridDataSource(xdata=test_xd, ydata=test_yd) r = DataRange2D() r.set_bounds((-1, -2), (3, 4)) assert_ary_(r.low, array([-1, -2])) assert_ary_(r.high, array([3, 4])) r.add(ds) assert_ary_(r.low, array([-1, -2])) r.low_setting = ('auto', 'auto') assert_ary_(r.low, array([-10, -10])) assert_ary_(r.high, array([3, 4])) r.high_setting = ('auto', 'auto') assert_ary_(r.low, array([-10, -10])) assert_ary_(r.high, array([10, 10])) r.set_bounds((-100, -100), (100, 100)) assert_ary_(r.low, array([-100, -100])) assert_ary_(r.high, array([100, 100]))
def setUp(self): # Set up plot component containing xs = np.arange(0, 5) ys = np.arange(0, 5) # Add some fake 2D data for the box's component index = GridDataSource(xdata=xs, ydata=ys, sort_order=('ascending', 'ascending')) index_mapper = GridMapper(range=DataRange2D(index)) color_source = ImageData(data=np.ones(shape=(5, 5)), depth=1) self.plot = CMapImagePlot( index=index, index_mapper=index_mapper, value=color_source, ) self.databox = DataBox( component=self.plot, data_position=[0, 0], ) self.plot.overlays.append(self.databox)
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()
def test_single_source(self): r = DataRange2D() x = arange(10.) y = arange(0., 100., 10.) ds = PointDataSource(transpose(array([x, y])), sort_order="none") r.add(ds) assert_ary_(r.low, array([0., 0.])) assert_ary_(r.high, array([9.0, 90.0])) r.low = [3.0, 30.0] r.high = [6.0, 60.0] assert_ary_(r.low_setting, array([3.0, 30.0])) assert_ary_(r.high_setting, array([6.0, 60.0])) assert_ary_(r.low, array([3.0, 30.0])) assert_ary_(r.high, array([6.0, 60.0])) r.refresh() assert_ary_(r.low_setting, array([3.0, 30.0])) assert_ary_(r.high_setting, array([6.0, 60.0])) assert_ary_(r.low, array([3.0, 30.0])) assert_ary_(r.high, array([6.0, 60.0])) r.low = ('auto', 'auto') self.assertTrue(r.low_setting == ('auto', 'auto')) assert_ary_(r.low, array([0.0, 0.0])) return
def test_mask_data(self): r = DataRange2D(low=[2.0, 5.0], high=[10.0, 18.0]) x = array([1, 3, 4, 9.8, 10.2, 12]) y = array([5, 3, 7, 12, 18, 6]) ary = transpose(array([x, y])) assert_equal(r.mask_data(ary), array([0, 0, 1, 1, 0, 0], 'b')) r = DataRange2D(low=[10., 15.], high=[20., 25.]) x = array([5, 10, 15, 20, 25, 30]) y = array([5, 10, 15, 20, 25, 30]) ary = transpose(array([x, y])) target_mask = array([0, 0, 1, 1, 0, 0], 'b') assert_equal(r.mask_data(ary), target_mask) assert_equal(r.mask_data(ary[::-1]), target_mask[::-1]) r = DataRange2D(low=[2.0, 5.0], high=[2.5, 9.0]) assert_equal(r.mask_data(ary), zeros(len(ary))) return
def create_plot(self): # Create the mapper, etc self._image_index = GridDataSource(array([]), array([]), sort_order=("ascending", "ascending")) image_index_range = DataRange2D(self._image_index) # self._image_index.on_trait_change(self._metadata_changed, # "metadata_changed") self._image_value = ImageData(data=array([]), value_depth=1) image_value_range = DataRange1D(self._image_value) # Create the colormapped scalar plot self.plot = CMapImagePlot( index=self._image_index, index_mapper=GridMapper(range=image_index_range), value=self._image_value, value_mapper=self._cmap(image_value_range)) # Add a left axis to the plot left = PlotAxis(orientation='left', title="y", mapper=self.plot.index_mapper._ymapper, component=self.plot) self.plot.overlays.append(left) # Add a bottom axis to the plot bottom = PlotAxis(orientation='bottom', title="x", mapper=self.plot.index_mapper._xmapper, component=self.plot) self.plot.overlays.append(bottom) # Add some tools to the plot self.plot.tools.append(PanTool(self.plot, constrain_key="shift")) self.plot.overlays.append( ZoomTool(component=self.plot, tool_mode="box", always_on=False)) # Create a colorbar cbar_index_mapper = LinearMapper(range=image_value_range) self.colorbar = ColorBar(index_mapper=cbar_index_mapper, plot=self.plot, padding_top=self.plot.padding_top, padding_bottom=self.plot.padding_bottom, padding_right=40, resizable='v', width=10) # Create a container and add components self.container = HPlotContainer(padding=40, fill_padding=True, bgcolor="white", use_backbuffer=False) self.container.add(self.colorbar) self.container.add(self.plot)
def test_multi_source(self): x = arange(10.) y = arange(0., 100., 10.) foo = transpose(array([x, y])) bar = transpose(array([y, x])) ds1 = PointDataSource(foo) ds2 = PointDataSource(bar) r = DataRange2D(ds1, ds2) assert_ary_(r.low, [0.0, 0.0]) assert_ary_(r.high, [90., 90.]) return
def _init_components(self): # Since this is called after the HasTraits constructor, we have to make # sure that we don't blow away any components that the caller may have # already set. if self.range2d is None: self.range2d = DataRange2D() if self.index_mapper is None: if self.index_scale == "linear": imap = LinearMapper(range=self.range2d.x_range) else: imap = LogMapper(range=self.range2d.x_range) self.index_mapper = imap if self.value_mapper is None: if self.value_scale == "linear": vmap = LinearMapper(range=self.range2d.y_range) else: vmap = LogMapper(range=self.range2d.y_range) self.value_mapper = vmap if self.x_ticks is None: self.x_ticks = ScalesTickGenerator( scale=self._make_scale(self.index_scale)) if self.y_ticks is None: self.y_ticks = ScalesTickGenerator( scale=self._make_scale(self.value_scale)) if self.x_grid is None: self.x_grid = PlotGrid(mapper=self.x_mapper, orientation="vertical", line_color="lightgray", line_style="dot", component=self, tick_generator=self.x_ticks) if self.y_grid is None: self.y_grid = PlotGrid(mapper=self.y_mapper, orientation="horizontal", line_color="lightgray", line_style="dot", component=self, tick_generator=self.y_ticks) if self.x_axis is None: self.x_axis = PlotAxis(mapper=self.x_mapper, orientation="bottom", component=self, tick_generator=self.x_ticks) if self.y_axis is None: self.y_axis = PlotAxis(mapper=self.y_mapper, orientation="left", component=self, tick_generator=self.y_ticks)
def test_range2d_changed(self): dv = DataView() ds = GridDataSource() dv.range2d.add(ds) old_range = dv.range2d r = DataRange2D() self.assertTrue(dv.range2d.sources==[ds]) dv.range2d = r self.assertTrue(dv.range2d.sources==[ds]) self.assertTrue(old_range.sources==[]) self.assertTrue(dv.range2d.x_range is dv.index_mapper.range) self.assertTrue(dv.range2d.y_range is dv.value_mapper.range)
def test_basic(self): x_ary = array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0]) y_ary = array([1.0, 1.0, 2.0, 2.0, 3.0, 3.0]) ds = GridDataSource(xdata=x_ary, ydata=y_ary) r = DataRange2D(ds) mapper = GridMapper(range=r) mapper.x_low_pos = 50 mapper.x_high_pos = 100 mapper.y_low_pos = 0 mapper.y_high_pos = 10 result = mapper.map_screen(transpose((x_ary, y_ary))) assert_equal(result, [(50, 0), (60, 0), (70, 5), (80, 5), (90, 10), (100, 10)])
def test_empty_range(self): r = DataRange2D() assert_ary_(r.low, array([-inf, -inf])) assert_ary_(r.high, array([inf, inf])) self.assertTrue(r.low_setting == ('auto', 'auto')) self.assertTrue(r.high_setting == ('auto', 'auto')) r.low = array([5.0, 5.0]) r.high = array([10.0, 10.0]) assert_ary_(r.low_setting, array([5.0, 5.0])) assert_ary_(r.high_setting, array([10.0, 10.0])) assert_ary_(r.low, array([5.0, 5.0])) assert_ary_(r.high, array([10.0, 10.0])) return
def empty_image(): """ Returns empty image plot """ from chaco.api import ImageData, GridDataSource, GridMapper, DataRange2D, ImagePlot image_source = ImageData.fromfile(config.IMG_NOCOMPLEX_PATH) w, h = image_source.get_width(), image_source.get_height() index = GridDataSource(np.arange(w), np.arange(h)) index_mapper = GridMapper( range=DataRange2D(low=(0, 0), high=(w - 1, h - 1))) image_plot = ImagePlot(index=index, value=image_source, index_mapper=index_mapper, origin='top left') return image_plot
def _corr_plot_default(self): diag = self.covar.diagonal() corr = self.covar / np.sqrt(np.outer(diag, diag)) N = len(diag) value_range = DataRange1D(low=-1, high=1) color_mapper = cmap(range=value_range) index = GridDataSource() value = ImageData() mapper = GridMapper(range=DataRange2D(index), y_low_pos=1.0, y_high_pos=0.0) index.set_data(xdata=np.arange(-0.5, N), ydata=np.arange(-0.5, N)) value.set_data(np.flipud(corr)) self.corr_data = value cmap_plot = CMapImagePlot(index=index, index_mapper=mapper, value=value, value_mapper=color_mapper, padding=(40, 40, 100, 40)) yaxis = PlotAxis( cmap_plot, orientation='left', tick_interval=1, tick_label_formatter=lambda x: self.header[int(N - 1 - x)], tick_generator=ShowAllTickGenerator(positions=np.arange(N))) xaxis = PlotAxis( cmap_plot, orientation='top', tick_interval=1, tick_label_formatter=lambda x: self.header[int(x)], tick_label_alignment='edge', tick_generator=ShowAllTickGenerator(positions=np.arange(N))) cmap_plot.overlays.append(yaxis) cmap_plot.overlays.append(xaxis) colorbar = ColorBar( index_mapper=LinearMapper(range=cmap_plot.value_range), plot=cmap_plot, orientation='v', resizable='v', width=10, padding=(40, 5, 100, 40)) container = HPlotContainer(bgcolor='transparent') container.add(cmap_plot) container.add(colorbar) return container
def test_reset_bounds(self): r = DataRange2D() low = (13, 42) high = (1337, 9001) r.set_bounds(low, high) self.assertEqual(r.low_setting, low) self.assertEqual(r.high_setting, high) r.reset() self.assertEqual(r.low_setting, ('auto', 'auto')) self.assertEqual(r.high_setting, ('auto', 'auto')) self.assertEqual(r.x_range.low_setting, 'auto') self.assertEqual(r.y_range.low_setting, 'auto') self.assertEqual(r.x_range.high_setting, 'auto') self.assertEqual(r.y_range.high_setting, 'auto')
def image_histogram_plot_component(self): xs = np.arange(0, len(self.im)) ys = np.arange(0, len(self.im[0])) index = GridDataSource(xdata=xs, ydata=ys, sort_order=('ascending', 'ascending')) index_mapper = GridMapper(range=DataRange2D(index)) color_source = ImageData(data=np.flipud(self.im), value_depth=1) reversed_grays = reverse(Greys) color_mapper = reversed_grays(DataRange1D(color_source)) plot = CMapImagePlot( index=index, index_mapper=index_mapper, value=color_source, value_mapper=color_mapper, ) #: Add overlay for zoom data_box_overlay = MyDataBox( component=plot, data_position=[0, 0], data_bounds=self.data_bounds, ) move_tool = MoveTool(component=data_box_overlay) resize_tool = ResizeTool(component=data_box_overlay) data_box_overlay.tools.append(move_tool) data_box_overlay.tools.append(resize_tool) data_box_overlay.on_trait_change(self.update_position, 'position') data_box_overlay.on_trait_change(self.update_data_bounds, 'bounds') #: Add to plot plot.overlays.append(data_box_overlay) return plot
def image_histogram_plot_component(self): xs = np.arange(0, len(self.im)) ys = np.arange(0, len(self.im[0])) index = GridDataSource(xdata=xs, ydata=ys, sort_order=('ascending', 'ascending')) index_mapper = GridMapper(range=DataRange2D(index)) color_source = ImageData(data=self.im, value_depth=1) reversed_grays = reverse(Greys) color_mapper = reversed_grays(DataRange1D(color_source)) plot = CMapImagePlot( index=index, index_mapper=index_mapper, value=color_source, value_mapper=color_mapper, orientation='h', origin='top left', ) self.data_box_overlay = DataBox( component=plot, data_position=[0, 0], data_bounds=[self.my_data_bounds, self.my_data_bounds], ) move_tool = MoveTool(component=self.data_box_overlay) self.data_box_overlay.tools.append(move_tool) self.data_box_overlay.on_trait_change(self.update_my_position, 'position') #: Add to plot plot.overlays.append(self.data_box_overlay) return plot
def get_image_index_and_mapper(image): h, w = image.shape[:2] index = GridDataSource(np.arange(h+1), np.arange(w+1)) index_mapper = GridMapper(range=DataRange2D(low=(0, 0), high=(h, w))) return index, index_mapper
def _plot2(self): print"...plotting line scans" title = str(self.plotE['plot']) + str(self.plotE["notes"]["start"]) self.plotdata5 = ArrayPlotData(imagedata = self.plotE['data']) self._image_index = GridDataSource(array([]), array([]), sort_order=("ascending","ascending")) self.xs = linspace(self.plotE["range"][0][0], self.plotE["range"][0][1], self.plotE["shape"][0]) self.ys = linspace(self.plotE["range"][1][0], self.plotE["range"][1][1], self.plotE["shape"][1]) self._image_index.set_data(self.xs, self.ys) image_index_range = DataRange2D(self._image_index) self._image_value = ImageData(data=array([]), value_depth=1) self._image_value.data = self.plotE['data'] image_value_range = DataRange1D(self._image_value) s = "" f = "" if self.x_s: s = "X" if self.y_s: s = "Y" if self.z_s: s = "Z" if self.x_f: f = "X" if self.y_f: f = "Y" if self.z_f: f = "Z" self.plot1lines = Plot(self.plotdata5, title = title) self.plot1lines.img_plot("imagedata", xbounds = (self.plotE["range"][0][0],self.plotE["range"][0][1]), ybounds = (self.plotE["range"][1][0],self.plotE["range"][1][1]), colormap=jet) img_plot = self.plot1lines.img_plot("imagedata")[0] imgtool = ImageInspectorTool(img_plot) img_plot.tools.append(imgtool) overlay = ImageInspectorOverlay(component=img_plot, image_inspector=imgtool, bgcolor="white", border_visible=True) self.plot1lines.overlays.append(overlay) ##ADD TOOLS self.plot1lines.tools.append(PanTool(self.plot1lines)) zoom1 = ZoomTool(component=self.plot1lines, tool_mode="box", always_on=False) self.plot1lines.overlays.append(zoom1) self.plot1lines.overlays.append(LineInspector(component=self.plot1lines, axis='index_x', inspect_mode="indexed", write_metadata=True, is_listener=False, #constrain_key="right", color="white")) self.plot1lines.overlays.append(LineInspector(component=self.plot1lines, axis='index_y', inspect_mode="indexed", write_metadata=True, color="white", is_listener=False)) ##ADD COLORBAR self.colorbar5 = ColorBar(index_mapper=LinearMapper(range=self.plot1lines.color_mapper.range), color_mapper=self.plot1lines.color_mapper, orientation='v', resizable='v', width=20, padding=5) self.colorbar5.plot = self.plot1lines self.colorbar5.tools.append(PanTool(self.colorbar5, constrain_direction="y", constrain=True)) self.zoom_overlay5 = ZoomTool(self.colorbar5, axis="index", tool_mode="range", always_on=True, drag_button="right") self.colorbar5.overlays.append(self.zoom_overlay5) self.pd = ArrayPlotData(line_index = array([]), line_value = array([])) self.slow_plot = Plot(self.pd, title = "Slowline : " + self.slowline) self.slow_plot.plot(("line_index", "line_value"), line_style='solid') self.pd.set_data("line_index2", array([])) self.pd.set_data("line_value2", array([])) self.fast_plot = Plot(self.pd, title = "Fastline : " + self.fastline) self.fast_plot.plot(("line_index2", "line_value2"), line_style='solid') self.pd.set_data("line_index", self.xs) self.pd.set_data("line_index2", self.ys) self.pd.set_data("line_value", self._image_value.data[self.fastscanline,:]) self.pd.set_data("line_value2", self._image_value.data[:,self.slowscanline]) self.colorbar5.padding= 0 self.colorbar5.padding_left = 15 #self.colorbar5.height = 400 self.colorbar5.padding_top =50 self.colorbar5.padding_bottom = 0 self.colorbar5.padding_right = 25 self.colorbar5.padding_left = 50 self.plot1lines.width = 300 self.plot1lines.padding_top = 50 self.plot1lines.index_axis.title = 'fast axis (um)' self.plot1lines.value_axis.title = 'slow axis (um)' self.slow_plot.width = 100 self.slow_plot.padding_right = 20 self.fast_plot.width = 100 self.fast_plot.padding_right = 20 self.container2 = GridPlotContainer(shape = (1,2), spacing = ((0,0)), use_backbuffer=True, valign = 'top', halign = 'center', bgcolor = 'white') self.container3 = GridPlotContainer(shape = (2,1), spacing = (0,0), use_backbuffer=True, valign = 'top', halign = 'center', bgcolor = 'grey') self.container4 = GridPlotContainer(shape = (1,2), spacing = (0,0), use_backbuffer=True, valign = 'top', halign = 'center', bgcolor = 'grey') self.container2.add(self.colorbar5) self.container3.add(self.fast_plot) self.container3.add(self.slow_plot) self.container4.add(self.container3) self.container4.add(self.plot1lines) self.container2.add(self.container4) self.LineScans = self.container2 self._readline_fired() self._scale_set_fired()
def __init__(self, x, y, z): super(ImagePlot, self).__init__() self.pd_all = ArrayPlotData(imagedata=z) #self.pd_horiz = ArrayPlotData(x=x, horiz=z[4, :]) #self.pd_vert = ArrayPlotData(y=y, vert=z[:,5]) self._imag_index = GridDataSource(xdata=x, ydata=y, sort_order=("ascending", "ascending")) index_mapper = GridMapper(range=DataRange2D(self._imag_index)) self._imag_index.on_trait_change(self._metadata_changed, "metadata_changed") self._image_value = ImageData(data=z, value_depth=1) color_mapper = jet(DataRange1D(self._image_value)) self.color_plot = CMapImagePlot(index=self._imag_index, index_mapper=index_mapper, value=self._image_value, value_mapper=color_mapper, padding=20, use_backbuffer=True, unified_draw=True) #Add axes to image plot left = PlotAxis(orientation='left', title="Frequency (GHz)", mapper=self.color_plot.index_mapper._ymapper, component=self.color_plot) self.color_plot.overlays.append(left) bottom = PlotAxis(orientation='bottom', title="Time (us)", mapper=self.color_plot.index_mapper._xmapper, component=self.color_plot) self.color_plot.overlays.append(bottom) self.color_plot.tools.append( PanTool(self.color_plot, constrain_key="shift")) self.color_plot.overlays.append( ZoomTool(component=self.color_plot, tool_mode="box", always_on=False)) #Add line inspector tool for horizontal and vertical self.color_plot.overlays.append( LineInspector(component=self.color_plot, axis='index_x', inspect_mode="indexed", write_metadata=True, is_listener=True, color="white")) self.color_plot.overlays.append( LineInspector(component=self.color_plot, axis='index_y', inspect_mode="indexed", write_metadata=True, color="white", is_listener=True)) myrange = DataRange1D(low=amin(z), high=amax(z)) cmap = jet self.colormap = cmap(myrange) # Create a colorbar cbar_index_mapper = LinearMapper(range=myrange) self.colorbar = ColorBar(index_mapper=cbar_index_mapper, plot=self.color_plot, padding_top=self.color_plot.padding_top, padding_bottom=self.color_plot.padding_bottom, padding_right=40, resizable='v', width=30) #, ytitle="Magvec (mV)") #create horizontal line plot self.horiz_cross_plot = Plot(self.pd_horiz, resizable="h") self.horiz_cross_plot.height = 100 self.horiz_cross_plot.padding = 20 self.horiz_cross_plot.plot(("x", "horiz")) #, #line_style="dot") # self.cross_plot.plot(("scatter_index","scatter_value","scatter_color"), # type="cmap_scatter", # name="dot", # color_mapper=self._cmap(image_value_range), # marker="circle", # marker_size=8) self.horiz_cross_plot.index_range = self.color_plot.index_range.x_range #create vertical line plot self.vert_cross_plot = Plot(self.pd_vert, width=140, orientation="v", resizable="v", padding=20, padding_bottom=160) self.vert_cross_plot.plot(("y", "vert")) #, # line_style="dot") # self.vert_cross_plot.xtitle="Magvec (mV)" # self.vertica_cross_plot.plot(("vertical_scatter_index", # "vertical_scatter_value", # "vertical_scatter_color"), # type="cmap_scatter", # name="dot", # color_mapper=self._cmap(image_value_range), # marker="circle", # marker_size=8) self.vert_cross_plot.index_range = self.color_plot.index_range.y_range # Create a container and add components self.container = HPlotContainer(padding=40, fill_padding=True, bgcolor="white", use_backbuffer=False) inner_cont = VPlotContainer(padding=0, use_backbuffer=True) inner_cont.add(self.horiz_cross_plot) inner_cont.add(self.color_plot) self.container.add(self.colorbar) self.container.add(inner_cont) self.container.add(self.vert_cross_plot)
def create_plot(self): # Create the mapper, etc self._image_index = GridDataSource(array([]), array([]), sort_order=("ascending","ascending")) image_index_range = DataRange2D(self._image_index) self._image_index.on_trait_change(self._metadata_changed, "metadata_changed") self._image_value = ImageData(data=array([]), value_depth=1) image_value_range = DataRange1D(self._image_value) # Create the contour plots self.polyplot = ContourPolyPlot(index=self._image_index, value=self._image_value, index_mapper=GridMapper(range= image_index_range), color_mapper=\ self._cmap(image_value_range), levels=self.num_levels) self.lineplot = ContourLinePlot(index=self._image_index, value=self._image_value, index_mapper=GridMapper(range= self.polyplot.index_mapper.range), levels=self.num_levels) # Add a left axis to the plot left = PlotAxis(orientation='left', title= "y", mapper=self.polyplot.index_mapper._ymapper, component=self.polyplot) self.polyplot.overlays.append(left) # Add a bottom axis to the plot bottom = PlotAxis(orientation='bottom', title= "x", mapper=self.polyplot.index_mapper._xmapper, component=self.polyplot) self.polyplot.overlays.append(bottom) # Add some tools to the plot self.polyplot.tools.append(PanTool(self.polyplot, constrain_key="shift")) self.polyplot.overlays.append(ZoomTool(component=self.polyplot, tool_mode="box", always_on=False)) self.polyplot.overlays.append(LineInspector(component=self.polyplot, axis='index_x', inspect_mode="indexed", write_metadata=True, is_listener=True, color="white")) self.polyplot.overlays.append(LineInspector(component=self.polyplot, axis='index_y', inspect_mode="indexed", write_metadata=True, color="white", is_listener=True)) # Add these two plots to one container contour_container = OverlayPlotContainer(padding=20, use_backbuffer=True, unified_draw=True) contour_container.add(self.polyplot) contour_container.add(self.lineplot) # Create a colorbar cbar_index_mapper = LinearMapper(range=image_value_range) self.colorbar = ColorBar(index_mapper=cbar_index_mapper, plot=self.polyplot, padding_top=self.polyplot.padding_top, padding_bottom=self.polyplot.padding_bottom, padding_right=40, resizable='v', width=30) self.pd = ArrayPlotData(line_index = array([]), line_value = array([]), scatter_index = array([]), scatter_value = array([]), scatter_color = array([])) self.cross_plot = Plot(self.pd, resizable="h") self.cross_plot.height = 100 self.cross_plot.padding = 20 self.cross_plot.plot(("line_index", "line_value"), line_style="dot") self.cross_plot.plot(("scatter_index","scatter_value","scatter_color"), type="cmap_scatter", name="dot", color_mapper=self._cmap(image_value_range), marker="circle", marker_size=8) self.cross_plot.index_range = self.polyplot.index_range.x_range self.pd.set_data("line_index2", array([])) self.pd.set_data("line_value2", array([])) self.pd.set_data("scatter_index2", array([])) self.pd.set_data("scatter_value2", array([])) self.pd.set_data("scatter_color2", array([])) self.cross_plot2 = Plot(self.pd, width = 140, orientation="v", resizable="v", padding=20, padding_bottom=160) self.cross_plot2.plot(("line_index2", "line_value2"), line_style="dot") self.cross_plot2.plot(("scatter_index2","scatter_value2","scatter_color2"), type="cmap_scatter", name="dot", color_mapper=self._cmap(image_value_range), marker="circle", marker_size=8) self.cross_plot2.index_range = self.polyplot.index_range.y_range # Create a container and add components self.container = HPlotContainer(padding=40, fill_padding=True, bgcolor = "white", use_backbuffer=False) inner_cont = VPlotContainer(padding=0, use_backbuffer=True) inner_cont.add(self.cross_plot) inner_cont.add(contour_container) self.container.add(self.colorbar) self.container.add(inner_cont) self.container.add(self.cross_plot2)
def setUp(self): self.x_ary = array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0]) self.y_ary = array([1.0, 1.0, 2.0, 2.0, 3.0, 3.0]) ds = GridDataSource(xdata=self.x_ary, ydata=self.y_ary) r = DataRange2D(ds) self.mapper = GridMapper(range=r)