Python bokeh.models.CategoricalColorMapper() Examples
The following are 13
code examples of bokeh.models.CategoricalColorMapper().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bokeh.models
, or try the search function
.
Example #1
Source File: testspikesplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_spikes_categorical_color_op(self): spikes = Spikes([(0, 0, 'A'), (0, 1, 'B'), (0, 2, 'C')], vdims=['y', 'color']).options(color='color') plot = bokeh_renderer.get_plot(spikes) cds = plot.handles['cds'] glyph = plot.handles['glyph'] cmapper = plot.handles['color_color_mapper'] self.assertTrue(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['A', 'B', 'C']) self.assertEqual(cds.data['color'], np.array(['A', 'B', 'C'])) self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
Example #2
Source File: testerrorbarplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_errorbars_categorical_color_op(self): errorbars = ErrorBars([(0, 0, 0.1, 0.2, 'A'), (0, 1, 0.2, 0.4, 'B'), (0, 2, 0.6, 1.2, 'C')], vdims=['y', 'perr', 'nerr', 'color']).options(color='color') plot = bokeh_renderer.get_plot(errorbars) cds = plot.handles['cds'] glyph = plot.handles['glyph'] cmapper = plot.handles['color_color_mapper'] self.assertTrue(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['A', 'B', 'C']) self.assertEqual(cds.data['color'], np.array(['A', 'B', 'C'])) self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
Example #3
Source File: testboxwhiskerplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_box_whisker_categorical_color_op(self): a = np.repeat(np.arange(5), 5) b = np.repeat(['A', 'B', 'C', 'D', 'E'], 5) box = BoxWhisker((a, b, np.arange(25)), ['a', 'b'], 'd').options(box_color='b') plot = bokeh_renderer.get_plot(box) source = plot.handles['vbar_1_source'] glyph = plot.handles['vbar_1_glyph'] cmapper = plot.handles['box_color_color_mapper'] self.assertEqual(source.data['box_color'], b[::5]) self.assertTrue(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['A', 'B', 'C', 'D', 'E']) self.assertEqual(glyph.fill_color, {'field': 'box_color', 'transform': cmapper})
Example #4
Source File: testvectorfieldplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_vectorfield_categorical_color_op(self): vectorfield = VectorField([(0, 0, 0, 1, 'A'), (0, 1, 0, 1, 'B'), (0, 2, 0, 1, 'C')], vdims=['A', 'M', 'color']).options(color='color') plot = bokeh_renderer.get_plot(vectorfield) cds = plot.handles['cds'] glyph = plot.handles['glyph'] cmapper = plot.handles['color_color_mapper'] self.assertTrue(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['A', 'B', 'C']) self.assertEqual(cds.data['color'], np.array(['A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C'])) self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
Example #5
Source File: testviolinplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_violin_categorical_color_op(self): a = np.repeat(np.arange(5), 5) b = np.repeat(['A', 'B', 'C', 'D', 'E'], 5) violin = Violin((a, b, np.arange(25)), ['a', 'b'], 'd').options(violin_color='b') plot = bokeh_renderer.get_plot(violin) source = plot.handles['patches_1_source'] glyph = plot.handles['patches_1_glyph'] cmapper = plot.handles['violin_color_color_mapper'] self.assertEqual(source.data['violin_color'], b[::5]) self.assertTrue(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['A', 'B', 'C', 'D', 'E']) self.assertEqual(glyph.fill_color, {'field': 'violin_color', 'transform': cmapper})
Example #6
Source File: testpointplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_points_colormapping_categorical(self): points = Points([(i, i*2, i*3, chr(65+i)) for i in range(10)], vdims=['a', 'b']).opts(plot=dict(color_index='b')) plot = bokeh_renderer.get_plot(points) plot.initialize_plot() cmapper = plot.handles['color_mapper'] self.assertIsInstance(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, list(points['b']))
Example #7
Source File: testpointplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_point_categorical_color_op(self): points = Points([(0, 0, 'A'), (0, 1, 'B'), (0, 2, 'C')], vdims='color').options(color='color') plot = bokeh_renderer.get_plot(points) cds = plot.handles['cds'] glyph = plot.handles['glyph'] cmapper = plot.handles['color_color_mapper'] self.assertTrue(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['A', 'B', 'C']) self.assertEqual(cds.data['color'], np.array(['A', 'B', 'C'])) self.assertEqual(glyph.fill_color, {'field': 'color', 'transform': cmapper}) self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
Example #8
Source File: testpointplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_point_categorical_dtype_color_op(self): df = pd.DataFrame(dict(sample_id=['subject 1', 'subject 2', 'subject 3', 'subject 4'], category=['apple', 'pear', 'apple', 'pear'], value=[1, 2, 3, 4])) df['category'] = df['category'].astype('category') points = Points(df, ['sample_id', 'value']).opts(color='category') plot = bokeh_renderer.get_plot(points) cds = plot.handles['cds'] glyph = plot.handles['glyph'] cmapper = plot.handles['color_color_mapper'] self.assertTrue(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['apple', 'pear']) self.assertEqual(np.asarray(cds.data['color']), np.array(['apple', 'pear', 'apple', 'pear'])) self.assertEqual(glyph.fill_color, {'field': 'color', 'transform': cmapper}) self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
Example #9
Source File: testpointplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_point_explicit_cmap_color_op(self): points = Points([(0, 0), (0, 1), (0, 2)]).options( color='y', cmap={0: 'red', 1: 'green', 2: 'blue'}) plot = bokeh_renderer.get_plot(points) cds = plot.handles['cds'] glyph = plot.handles['glyph'] cmapper = plot.handles['color_color_mapper'] self.assertTrue(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['0', '1', '2']) self.assertEqual(cmapper.palette, ['red', 'green', 'blue']) self.assertEqual(cds.data['color_str__'], ['0', '1', '2']) self.assertEqual(glyph.fill_color, {'field': 'color_str__', 'transform': cmapper}) self.assertEqual(glyph.line_color, {'field': 'color_str__', 'transform': cmapper})
Example #10
Source File: testlabels.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_label_categorical_color_op(self): labels = Labels([(0, 0, 'A'), (0, 1, 'B'), (0, 2, 'C')], vdims='color').options(text_color='color') plot = bokeh_renderer.get_plot(labels) cds = plot.handles['cds'] glyph = plot.handles['glyph'] cmapper = plot.handles['text_color_color_mapper'] self.assertTrue(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['A', 'B', 'C']) self.assertEqual(cds.data['text_color'], np.array(['A', 'B', 'C'])) self.assertEqual(glyph.text_color, {'field': 'text_color', 'transform': cmapper})
Example #11
Source File: testhistogramplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_histogram_categorical_color_op(self): histogram = Histogram([(0, 0, 'A'), (0, 1, 'B'), (0, 2, 'C')], vdims=['y', 'color']).options(color='color') plot = bokeh_renderer.get_plot(histogram) cds = plot.handles['cds'] glyph = plot.handles['glyph'] cmapper = plot.handles['color_color_mapper'] self.assertTrue(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['A', 'B', 'C']) self.assertEqual(cds.data['color'], np.array(['A', 'B', 'C'])) self.assertEqual(glyph.fill_color, {'field': 'color', 'transform': cmapper}) self.assertEqual(glyph.line_color, 'black')
Example #12
Source File: testpathplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_polygons_categorical_color_op(self): polygons = Polygons([ {('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(polygons) cds = plot.handles['source'] glyph = plot.handles['glyph'] cmapper = plot.handles['color_color_mapper'] self.assertEqual(glyph.line_color, 'black') self.assertEqual(glyph.fill_color, {'field': 'color', 'transform': cmapper}) self.assertEqual(cds.data['color'], np.array(['b', 'a'])) self.assertIsInstance(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['b', 'a'])
Example #13
Source File: testpathplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
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'])