def test_bounds_index(self): # ascending bounds = self.data_source.get_bounds(index=0) self.assertEqual(bounds, (0, 1)) # descending myarray = arange(20)[::-1].reshape(10, 2) data_source = MultiArrayDataSource(myarray, sort_order='descending') bounds = data_source.get_bounds(index=0) self.assertEqual(bounds, (18, 19)) # no order myarray = array([[12, 3], [0, 9], [2, 18], [3, 10]]) data_source = MultiArrayDataSource(myarray, sort_order="none") bounds = data_source.get_bounds(index=0) self.assertEqual(bounds, (3, 12))
def test_init_defaults(self): data_source = MultiArrayDataSource() assert_array_equal(data_source._data, empty(shape=(0, 1), dtype=float)) # XXX this doesn't match AbstractDataSource's interface self.assertEqual(data_source.value_dimension, 1) self.assertEqual(data_source.sort_order, "ascending") self.assertFalse(data_source.is_masked())
def test_bounds_all_nans(self): myarray = empty((10, 2)) myarray[:, :] = nan data_source = MultiArrayDataSource(myarray) bounds = data_source.get_bounds() self.assertTrue(isnan(bounds[0])) self.assertTrue(isnan(bounds[1]))
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 test_get_data_no_data(self): data_source = MultiArrayDataSource() assert_array_equal(data_source.get_data(), empty(shape=(0, 1), dtype=float))
def setUp(self): self.myarray = arange(20).reshape(10, 2) self.data_source = MultiArrayDataSource(self.myarray)
def test_bounds_empty(self): data_source = MultiArrayDataSource() bounds = data_source.get_bounds() # XXX this is sort of inconsistent with test_bounds_all_nans() self.assertEqual(bounds, (0, 0))
def _get_plot_multiline(self): if self.data is None or len(self.data.shape) == 1: return numpoints = self.data.shape[1] if self.scale_type == 'Time': index_x = self._create_dates(numpoints, start=self.first_day) else: index_x = np.arange(numpoints) index_y = np.linspace(1, self.data.shape[0], self.data.shape[0]) xs = ArrayDataSource(index_x) xrange = DataRange1D() xrange.add(xs) ys = ArrayDataSource(index_y) yrange = DataRange1D() yrange.add(ys) # The data source for the MultiLinePlot. ds = MultiArrayDataSource(data=self.data) corr_plot = \ MultiLinePlot( index=xs, yindex=ys, index_mapper=LinearMapper(range=xrange), value_mapper=LinearMapper(range=yrange), value=ds, global_max=self.data.max(), global_min=self.data.min()) corr_plot.value_mapper.range.low = 0 corr_plot.value_mapper.range.high = self.data.shape[0] + 1 self.multi_line_plot_renderer = corr_plot plot = Plot(title=self.p_title) if self.scale_type == 'Time': # Just the last axis shows tick_labels bottom_axis = PlotAxis(component=plot, orientation="bottom", title=self.x_lbl, tick_generator=ScalesTickGenerator( scale=CalendarScaleSystem())) else: bottom_axis = PlotAxis(orientation='bottom', title=self.x_lbl, title_font="modern 12", tick_visible=True, small_axis_style=True, axis_line_visible=False, component=plot) if self.y_lbl_type == 'Custom' and \ len(self.y_labels) == self.data.shape[0]: # a new value in the list defaults to None so raise an error before # the operator ends inputing it. left_axis = LabelAxis(component=plot, orientation='left', title=self.x_lbl, mapper=corr_plot.value_mapper, tick_interval=1.0, labels=self.y_labels, positions=index_y) else: left_axis = PlotAxis( component=plot, orientation='left', title=self.y_lbl, title_font="modern 12", #title_spacing=0, tick_label_font="modern 8", tick_visible=True, small_axis_style=True, axis_line_visible=False, ensure_labels_bounded=True, #tick_label_color="transparent", mapper=corr_plot.value_mapper) plot.overlays.extend([bottom_axis, left_axis]) plot.add(corr_plot) plot.padding_bottom = 50 return plot