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 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 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())
Пример #5
0
		def __init__(self,data_q,num):
			super(PlotterWindow,self).__init__()

			self.data_q = data_q

			self.x = ArrayDataSource(zeros(num))
			self.y = ArrayDataSource(zeros(num))
			self.v = MultiArrayDataSource(zeros((num,2)))

			xrange = DataRange1D()
			xrange.add(self.x)
			yrange = DataRange1D()
			yrange.add(self.y)

			quiverplot = QuiverPlot(index=self.x,value=self.y,vectors=self.v,
				index_mapper=LinearMapper(range=xrange),
				value_mapper=LinearMapper(range=yrange),
				bgcolor='white')
			add_default_axes(quiverplot)
			add_default_grids(quiverplot)

			quiverplot.tools.append(PanTool(quiverplot,constrain_key='shift'))
			quiverplot.overlays.append(ZoomTool(quiverplot))

			self.plot = OverlayPlotContainer(quiverplot, padding=50)
			self.timer = Timer(50.0, self.onTimer)

			self.configure_traits()
Пример #6
0
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_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))
Пример #8
0
	class PlotterWindow(HasTraits):
		plot = Instance(OverlayPlotContainer)
		timer = Instance(Timer)

		traits_view = View(
			Item('plot',editor=ComponentEditor(),show_label=False),
			width=500,height=500,resizable=True,title="Plotter")

		def __init__(self,data_q,num):
			super(PlotterWindow,self).__init__()

			self.data_q = data_q

			self.x = ArrayDataSource(zeros(num))
			self.y = ArrayDataSource(zeros(num))
			self.v = MultiArrayDataSource(zeros((num,2)))

			xrange = DataRange1D()
			xrange.add(self.x)
			yrange = DataRange1D()
			yrange.add(self.y)

			quiverplot = QuiverPlot(index=self.x,value=self.y,vectors=self.v,
				index_mapper=LinearMapper(range=xrange),
				value_mapper=LinearMapper(range=yrange),
				bgcolor='white')
			add_default_axes(quiverplot)
			add_default_grids(quiverplot)

			quiverplot.tools.append(PanTool(quiverplot,constrain_key='shift'))
			quiverplot.overlays.append(ZoomTool(quiverplot))

			self.plot = OverlayPlotContainer(quiverplot, padding=50)
			self.timer = Timer(50.0, self.onTimer)

			self.configure_traits()

		def onTimer(self,*args):
			d = self.data_q.get()

			self.x.set_data(d[0])
			self.y.set_data(d[1])
			self.v.set_data(d[2])
Пример #9
0
  def _plot_default(self):

    # Array data sources, each single element arrays
    x_ds = ArrayDataSource([self.robot.x])
    y_ds = ArrayDataSource([self.robot.y])

    vector_ds = MultiArrayDataSource()
    vector_ds.set_data(self.vector)

    # Set up the ranges for the plot explicitly (no autosizing)
    x_r = DataRange1D(x_ds)
    x_r.set_bounds(0,self.xsize)
    y_r = DataRange1D(y_ds)
    y_r.set_bounds(0,self.ysize)

    plot = QuiverPlot(index = x_ds, value = y_ds,
                    vectors = vector_ds,
                    index_mapper = LinearMapper(range=x_r),
                    value_mapper = LinearMapper(range=y_r),
                    bgcolor = "white", line_color = self.color, line_width = 2.0)

    plot.aspect_ratio = float(self.xsize) / float(self.ysize)
    return plot
    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_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 test_get_data_no_data(self):
        data_source = MultiArrayDataSource()

        assert_array_equal(data_source.get_data(),
                           empty(shape=(0, 1), dtype=float))
class MultiArrayDataTestCase(UnittestTools, unittest.TestCase):
    def setUp(self):
        self.myarray = arange(20).reshape(10, 2)
        self.data_source = MultiArrayDataSource(self.myarray)

    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_basic_setup(self):
        assert_array_equal(self.myarray, self.data_source._data)
        # XXX this doesn't match AbstractDataSource's interface
        self.assertEqual(self.data_source.index_dimension, 0)
        self.assertEqual(self.data_source.value_dimension, 1)
        self.assertEqual(self.data_source.sort_order, "ascending")
        self.assertFalse(self.data_source.is_masked())

    def test_set_data(self):
        new_array = arange(0, 40, 2).reshape(10, 2)

        with self.assertTraitChanges(self.data_source, 'data_changed',
                                     count=1):
            self.data_source.set_data(new_array)

        assert_array_equal(new_array, self.data_source._data)
        self.assertEqual(self.data_source.get_bounds(), (0, 38))
        self.assertEqual(self.data_source.sort_order, "ascending")

    def test_get_data(self):
        assert_array_equal(self.myarray, self.data_source.get_data())

    def test_get_data_axes(self):
        assert_array_equal(arange(0, 20, 2), self.data_source.get_data(axes=0))

    def test_get_data_no_data(self):
        data_source = MultiArrayDataSource()

        assert_array_equal(data_source.get_data(),
                           empty(shape=(0, 1), dtype=float))

    def test_get_data_mask(self):
        data, mask = self.data_source.get_data_mask()
        assert_array_equal(data, self.myarray)
        assert_array_equal(mask, ones(shape=(10, 2), dtype=bool))

    def test_bounds(self):
        # ascending
        bounds = self.data_source.get_bounds()
        self.assertEqual(bounds, (0, 19))

        # descending
        myarray = arange(20)[::-1].reshape(10, 2)
        data_source = MultiArrayDataSource(myarray, sort_order='descending')
        bounds = data_source.get_bounds()
        self.assertEqual(bounds, (0, 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()
        self.assertEqual(bounds, (0, 18))

    def test_bounds_value(self):
        # ascending
        bounds = self.data_source.get_bounds(value=0)
        self.assertEqual(bounds, (0, 18))

        # descending
        myarray = arange(20)[::-1].reshape(10, 2)
        data_source = MultiArrayDataSource(myarray, sort_order='descending')
        bounds = data_source.get_bounds(value=0)
        self.assertEqual(bounds, (1, 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(value=0)
        self.assertEqual(bounds, (0, 12))

    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_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 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 test_metadata(self):
        self.assertEqual(self.data_source.metadata, {
            'annotations': [],
            'selections': []
        })

    @unittest.skip('change handler missing from class')
    def test_metadata_changed(self):
        with self.assertTraitChanges(self.data_source,
                                     'metadata_changed',
                                     count=1):
            self.data_source.metadata = {'new_metadata': True}

    @unittest.skip('change handler missing from class')
    def test_metadata_items_changed(self):
        with self.assertTraitChanges(self.data_source,
                                     'metadata_changed',
                                     count=1):
            self.data_source.metadata['new_metadata'] = True
 def setUp(self):
     self.myarray = arange(20).reshape(10, 2)
     self.data_source = MultiArrayDataSource(self.myarray)
class MultiArrayDataTestCase(UnittestTools, unittest.TestCase):

    def setUp(self):
        self.myarray = arange(20).reshape(10, 2)
        self.data_source = MultiArrayDataSource(self.myarray)

    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_basic_setup(self):
        assert_array_equal(self.myarray, self.data_source._data)
        # XXX this doesn't match AbstractDataSource's interface
        self.assertEqual(self.data_source.index_dimension, 0)
        self.assertEqual(self.data_source.value_dimension, 1)
        self.assertEqual(self.data_source.sort_order, "ascending")
        self.assertFalse(self.data_source.is_masked())

    def test_set_data(self):
        new_array = arange(0, 40, 2).reshape(10, 2)

        with self.assertTraitChanges(self.data_source, 'data_changed', count=1):
            self.data_source.set_data(new_array)

        assert_array_equal(new_array, self.data_source._data)
        self.assertEqual(self.data_source.get_bounds(), (0, 38))
        self.assertEqual(self.data_source.sort_order, "ascending")

    def test_get_data(self):
        assert_array_equal(self.myarray, self.data_source.get_data())

    def test_get_data_axes(self):
        assert_array_equal(arange(0, 20, 2), self.data_source.get_data(axes=0))

    def test_get_data_no_data(self):
        data_source = MultiArrayDataSource()

        assert_array_equal(data_source.get_data(),
                           empty(shape=(0, 1), dtype=float))

    def test_get_data_mask(self):
        data, mask = self.data_source.get_data_mask()
        assert_array_equal(data, self.myarray)
        assert_array_equal(mask, ones(shape=(10, 2), dtype=bool))

    def test_bounds(self):
        # ascending
        bounds = self.data_source.get_bounds()
        self.assertEqual(bounds, (0, 19))

        # descending
        myarray = arange(20)[::-1].reshape(10, 2)
        data_source = MultiArrayDataSource(myarray, sort_order='descending')
        bounds = data_source.get_bounds()
        self.assertEqual(bounds, (0, 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()
        self.assertEqual(bounds, (0, 18))

    def test_bounds_value(self):
        # ascending
        bounds = self.data_source.get_bounds(value=0)
        self.assertEqual(bounds, (0, 18))

        # descending
        myarray = arange(20)[::-1].reshape(10, 2)
        data_source = MultiArrayDataSource(myarray, sort_order='descending')
        bounds = data_source.get_bounds(value=0)
        self.assertEqual(bounds, (1, 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(value=0)
        self.assertEqual(bounds, (0, 12))

    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_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 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 test_metadata(self):
        self.assertEqual(self.data_source.metadata,
                         {'annotations': [], 'selections': []})

    @unittest.skip('change handler missing from class')
    def test_metadata_changed(self):
        with self.assertTraitChanges(self.data_source, 'metadata_changed', count=1):
            self.data_source.metadata = {'new_metadata': True}

    @unittest.skip('change handler missing from class')
    def test_metadata_items_changed(self):
        with self.assertTraitChanges(self.data_source, 'metadata_changed', count=1):
            self.data_source.metadata['new_metadata'] = True
 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 setUp(self):
     self.myarray = arange(20).reshape(10, 2)
     self.data_source = MultiArrayDataSource(self.myarray)
    def test_get_data_no_data(self):
        data_source = MultiArrayDataSource()

        assert_array_equal(data_source.get_data(),
                           empty(shape=(0, 1), dtype=float))
Пример #19
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