Esempio n. 1
0
 def test_contours_color_op(self):
     contours = Contours([{
         ('x', 'y'): [(0, 0), (0, 1), (1, 0)],
         'color': 'green'
     }, {
         ('x', 'y'): [(1, 0), (1, 1), (0, 1)],
         'color': 'red'
     }],
                         vdims='color').options(color='color')
     plot = mpl_renderer.get_plot(contours)
     artist = plot.handles['artist']
     colors = np.array([[0., 0.501961, 0., 1.], [1., 0., 0., 1.]])
     self.assertEqual(artist.get_edgecolors(), colors)
Esempio n. 2
0
 def test_contours_linear_color_op(self):
     contours = Contours([{
         ('x', 'y'): [(0, 0), (0, 1), (1, 0)],
         'color': 7
     }, {
         ('x', 'y'): [(1, 0), (1, 1), (0, 1)],
         'color': 3
     }],
                         vdims='color').options(color='color')
     plot = mpl_renderer.get_plot(contours)
     artist = plot.handles['artist']
     self.assertEqual(artist.get_array(), np.array([7, 3]))
     self.assertEqual(artist.get_clim(), (3, 7))
Esempio n. 3
0
 def test_contours_categorical_color_op(self):
     contours = Contours([{
         ('x', 'y'): [(0, 0), (0, 1), (1, 0)],
         'color': 'b'
     }, {
         ('x', 'y'): [(1, 0), (1, 1), (0, 1)],
         'color': 'a'
     }],
                         vdims='color').options(color='color')
     plot = mpl_renderer.get_plot(contours)
     artist = plot.handles['artist']
     self.assertEqual(artist.get_array(), np.array([0, 1]))
     self.assertEqual(artist.get_clim(), (0, 1))
Esempio n. 4
0
 def test_contours_categorical_color_op(self):
     contours = Contours([
         {('x', 'y'): [(0, 0), (0, 1), (1, 0)], 'color': 'b'},
         {('x', 'y'): [(1, 0), (1, 1), (0, 1)], 'color': 'a'}
     ], vdims='color').options(color='color')
     plot = bokeh_renderer.get_plot(contours)
     cds = plot.handles['source']
     glyph = plot.handles['glyph']
     cmapper = plot.handles['color_color_mapper']
     self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
     self.assertEqual(cds.data['color'], np.array(['b', 'a']))
     self.assertIsInstance(cmapper, CategoricalColorMapper)
     self.assertEqual(cmapper.factors, ['b', 'a'])
Esempio n. 5
0
 def test_contours_linear_color_op(self):
     contours = Contours([
         {('x', 'y'): [(0, 0), (0, 1), (1, 0)], 'color': 7},
         {('x', 'y'): [(1, 0), (1, 1), (0, 1)], 'color': 3}
     ], vdims='color').options(color='color')
     plot = bokeh_renderer.get_plot(contours)
     cds = plot.handles['source']
     glyph = plot.handles['glyph']
     cmapper = plot.handles['color_color_mapper']
     self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
     self.assertEqual(cds.data['color'], np.array([7, 3]))
     self.assertIsInstance(cmapper, LinearColorMapper)
     self.assertEqual(cmapper.low, 3)
     self.assertEqual(cmapper.high, 7)
Esempio n. 6
0
 def test_contours_linear_color_op_update(self):
     contours = HoloMap({
         0: Contours([
             {('x', 'y'): [(0, 0), (0, 1), (1, 0)], 'color': 7},
             {('x', 'y'): [(1, 0), (1, 1), (0, 1)], 'color': 3}
         ], vdims='color'),
         1: Contours([
             {('x', 'y'): [(0, 0), (0, 1), (1, 0)], 'color': 5},
             {('x', 'y'): [(1, 0), (1, 1), (0, 1)], 'color': 2}
         ], vdims='color')}).options(color='color', framewise=True)
     plot = bokeh_renderer.get_plot(contours)
     cds = plot.handles['source']
     glyph = plot.handles['glyph']
     cmapper = plot.handles['color_color_mapper']
     plot.update((0,))
     self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
     self.assertEqual(cds.data['color'], np.array([7, 3]))
     self.assertEqual(cmapper.low, 3)
     self.assertEqual(cmapper.high, 7)
     plot.update((1,))
     self.assertEqual(cds.data['color'], np.array([5, 2]))
     self.assertEqual(cmapper.low, 2)
     self.assertEqual(cmapper.high, 5)
 def test_contours_alpha_op(self):
     contours = Contours([{
         ('x', 'y'): [(0, 0), (0, 1), (1, 0)],
         'alpha': 0.7
     }, {
         ('x', 'y'): [(1, 0), (1, 1), (0, 1)],
         'alpha': 0.3
     }],
                         vdims='alpha').options(alpha='alpha')
     plot = bokeh_renderer.get_plot(contours)
     cds = plot.handles['source']
     glyph = plot.handles['glyph']
     self.assertEqual(glyph.line_alpha, {'field': 'alpha'})
     self.assertEqual(cds.data['alpha'], np.array([0.7, 0.3]))
 def test_contours_color_op(self):
     contours = Contours([{
         ('x', 'y'): [(0, 0), (0, 1), (1, 0)],
         'color': 'green'
     }, {
         ('x', 'y'): [(1, 0), (1, 1), (0, 1)],
         'color': 'red'
     }],
                         vdims='color').options(color='color')
     plot = bokeh_renderer.get_plot(contours)
     cds = plot.handles['source']
     glyph = plot.handles['glyph']
     self.assertEqual(glyph.line_color, {'field': 'color'})
     self.assertEqual(cds.data['color'], np.array(['green', 'red']))
 def test_contours_line_width_op(self):
     contours = Contours(
         [{
             ('x', 'y'): [(0, 0), (0, 1), (1, 0)],
             'line_width': 7
         }, {
             ('x', 'y'): [(1, 0), (1, 1), (0, 1)],
             'line_width': 3
         }],
         vdims='line_width').options(line_width='line_width')
     plot = bokeh_renderer.get_plot(contours)
     cds = plot.handles['source']
     glyph = plot.handles['glyph']
     self.assertEqual(glyph.line_width, {'field': 'line_width'})
     self.assertEqual(cds.data['line_width'], np.array([7, 3]))
Esempio n. 10
0
    def setUp(self):
        self.img_fn = lambda: Image(np.random.rand(10, 10))
        self.contour_fn = lambda: Contours([np.random.rand(10, 2)
                                            for i in range(2)])
        params = [list(range(3)) for i in range(2)]
        self.img_map = HoloMap({(i, j): self.img_fn()
                                for i, j in product(*params)},
                               key_dimensions=['a', 'b'])
        self.contour_map = HoloMap({(i, j): self.contour_fn()
                                    for i, j in product(*params)},
                                   key_dimensions=['a', 'b'])
        self.ndoverlay_map = self.img_map.overlay('b')
        self.overlay_map = self.img_map * self.contour_map
        self.layout_map = self.ndoverlay_map + self.contour_map
        self.duplicate_map = self.img_map.clone(key_dimensions=['x', 'y'])

        self.overlap1 = HoloMap({i: self.img_fn() for i in range(5)})
        self.overlap2 = HoloMap({i: self.img_fn() for i in range(10)})
        self.overlap_layout = self.overlap1 + self.overlap2
Esempio n. 11
0
 def test_contours_empty_path(self):
     import pandas as pd
     contours = Contours([
         pd.DataFrame([], columns=['x', 'y', 'color', 'line_width']),
         pd.DataFrame(
             {
                 'x': np.random.rand(10),
                 'y': np.random.rand(10),
                 'color': ['red'] * 10,
                 'line_width': [3] * 10
             },
             columns=['x', 'y', 'color', 'line_width'])
     ],
                         vdims=['color',
                                'line_width']).opts(color='color',
                                                    line_width='line_width')
     plot = bokeh_renderer.get_plot(contours)
     glyph = plot.handles['glyph']
     self.assertEqual(glyph.line_color, 'red')
     self.assertEqual(glyph.line_width, 3)