當前位置: 首頁>>代碼示例>>Python>>正文


Python models.CategoricalColorMapper方法代碼示例

本文整理匯總了Python中bokeh.models.CategoricalColorMapper方法的典型用法代碼示例。如果您正苦於以下問題:Python models.CategoricalColorMapper方法的具體用法?Python models.CategoricalColorMapper怎麽用?Python models.CategoricalColorMapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bokeh.models的用法示例。


在下文中一共展示了models.CategoricalColorMapper方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_spikes_categorical_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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}) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:13,代碼來源:testspikesplot.py

示例2: test_errorbars_categorical_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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}) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:13,代碼來源:testerrorbarplot.py

示例3: test_box_whisker_categorical_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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}) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:14,代碼來源:testboxwhiskerplot.py

示例4: test_vectorfield_categorical_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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}) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:13,代碼來源:testvectorfieldplot.py

示例5: test_violin_categorical_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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}) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:14,代碼來源:testviolinplot.py

示例6: test_points_colormapping_categorical

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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'])) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:10,代碼來源:testpointplot.py

示例7: test_point_categorical_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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}) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:14,代碼來源:testpointplot.py

示例8: test_point_categorical_dtype_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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}) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:15,代碼來源:testpointplot.py

示例9: test_point_explicit_cmap_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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}) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:15,代碼來源:testpointplot.py

示例10: test_label_categorical_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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}) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:13,代碼來源:testlabels.py

示例11: test_histogram_categorical_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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') 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:14,代碼來源:testhistogramplot.py

示例12: test_polygons_categorical_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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']) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:16,代碼來源:testpathplot.py

示例13: test_contours_categorical_color_op

# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import CategoricalColorMapper [as 別名]
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']) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:15,代碼來源:testpathplot.py


注:本文中的bokeh.models.CategoricalColorMapper方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。