Esempio n. 1
0
 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])
Esempio n. 2
0
 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]))
Esempio n. 3
0
 def test_reversed(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=100, high_pos=0)
     result = mapper.map_screen(ary)
     assert_array_almost_equal(result, array([100, 75, 50, 25, 0]))
Esempio n. 4
0
 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])
Esempio n. 5
0
 def test_nan(self):
     ary = array([1.0, nan, 10.0, nan, 100.0, 1000.0])
     ds = ArrayDataSource(ary)
     r = DataRange1D(ds)
     mapper = LogMapper(range=r, low_pos=0, high_pos=30)
     mapper.fill_value = 100.0
     result = mapper.map_screen(ary)
     assert_array_almost_equal(result, [0, 20, 10, 20, 20, 30])
Esempio n. 6
0
 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]))
     return
Esempio n. 7
0
 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])
     return
Esempio n. 8
0
 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])
     return
Esempio n. 9
0
 def test_reversed(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=100, high_pos=0)
     result = mapper.map_screen(ary)
     assert_array_almost_equal(result, array([100, 75, 50, 25, 0]))
     return
Esempio n. 10
0
 def test_fill_value(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)
     # This causes out-of-bounds values to be treated as the value 100.0
     mapper.fill_value = 100.0
     result = mapper.map_screen(ary)
     assert_array_almost_equal(result, [0, 20, 20, 10, 20, 30])
Esempio n. 11
0
 def test_fill_value(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)
     # This causes out-of-bounds values to be treated as the value 100.0
     mapper.fill_value = 100.0
     result = mapper.map_screen(ary)
     assert_array_almost_equal(result, [0, 20, 20, 10, 20, 30])
     return
Esempio n. 12
0
    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)
Esempio n. 13
0
 def _colorbar_scale_changed(self):
     rng = self.colorbar.index_mapper.range
     dlim = self.colorbar.index_mapper.domain_limits
     if self.colorbar_scale == 'linear':
         new_mapper = LinearMapper(range=rng, domain_limits=dlim)
     else:  # 'log'
         new_mapper = LogMapper(range=rng, domain_limits=dlim)
     self.colorbar.index_mapper = new_mapper