本文整理汇总了Python中bokeh.models.LinearColorMapper方法的典型用法代码示例。如果您正苦于以下问题:Python models.LinearColorMapper方法的具体用法?Python models.LinearColorMapper怎么用?Python models.LinearColorMapper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bokeh.models
的用法示例。
在下文中一共展示了models.LinearColorMapper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visualize_sentences
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def visualize_sentences(vecs, sentences, palette="Viridis256", filename="/notebooks/embedding/sentences.png",
use_notebook=False):
tsne = TSNE(n_components=2)
tsne_results = tsne.fit_transform(vecs)
df = pd.DataFrame(columns=['x', 'y', 'sentence'])
df['x'], df['y'], df['sentence'] = tsne_results[:, 0], tsne_results[:, 1], sentences
source = ColumnDataSource(ColumnDataSource.from_df(df))
labels = LabelSet(x="x", y="y", text="sentence", y_offset=8,
text_font_size="12pt", text_color="#555555",
source=source, text_align='center')
color_mapper = LinearColorMapper(palette=palette, low=min(tsne_results[:, 1]), high=max(tsne_results[:, 1]))
plot = figure(plot_width=900, plot_height=900)
plot.scatter("x", "y", size=12, source=source, color={'field': 'y', 'transform': color_mapper}, line_color=None, fill_alpha=0.8)
plot.add_layout(labels)
if use_notebook:
output_notebook()
show(plot)
else:
export_png(plot, filename)
print("save @ " + filename)
示例2: visualize_words
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def visualize_words(words, vecs, palette="Viridis256", filename="/notebooks/embedding/words.png",
use_notebook=False):
tsne = TSNE(n_components=2)
tsne_results = tsne.fit_transform(vecs)
df = pd.DataFrame(columns=['x', 'y', 'word'])
df['x'], df['y'], df['word'] = tsne_results[:, 0], tsne_results[:, 1], list(words)
source = ColumnDataSource(ColumnDataSource.from_df(df))
labels = LabelSet(x="x", y="y", text="word", y_offset=8,
text_font_size="15pt", text_color="#555555",
source=source, text_align='center')
color_mapper = LinearColorMapper(palette=palette, low=min(tsne_results[:, 1]), high=max(tsne_results[:, 1]))
plot = figure(plot_width=900, plot_height=900)
plot.scatter("x", "y", size=12, source=source, color={'field': 'y', 'transform': color_mapper}, line_color=None,
fill_alpha=0.8)
plot.add_layout(labels)
if use_notebook:
output_notebook()
show(plot)
else:
export_png(plot, filename)
print("save @ " + filename)
示例3: visualize_between_sentences
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def visualize_between_sentences(sentences, vec_list, palette="Viridis256",
filename="/notebooks/embedding/between-sentences.png",
use_notebook=False):
df_list, score_list = [], []
for sent1_idx, sentence1 in enumerate(sentences):
for sent2_idx, sentence2 in enumerate(sentences):
vec1, vec2 = vec_list[sent1_idx], vec_list[sent2_idx]
if np.any(vec1) and np.any(vec2):
score = cosine_similarity(X=[vec1], Y=[vec2])
df_list.append({'x': sentence1, 'y': sentence2, 'similarity': score[0][0]})
score_list.append(score[0][0])
df = pd.DataFrame(df_list)
color_mapper = LinearColorMapper(palette=palette, low=np.max(score_list), high=np.min(score_list))
TOOLS = "hover,save,pan,box_zoom,reset,wheel_zoom"
p = figure(x_range=sentences, y_range=list(reversed(sentences)),
x_axis_location="above", plot_width=900, plot_height=900,
toolbar_location='below', tools=TOOLS,
tooltips=[('sentences', '@x @y'), ('similarity', '@similarity')])
p.grid.grid_line_color = None
p.axis.axis_line_color = None
p.axis.major_tick_line_color = None
p.axis.major_label_standoff = 0
p.xaxis.major_label_orientation = 3.14 / 3
p.rect(x="x", y="y", width=1, height=1,
source=df,
fill_color={'field': 'similarity', 'transform': color_mapper},
line_color=None)
color_bar = ColorBar(ticker=BasicTicker(desired_num_ticks=5),
color_mapper=color_mapper, major_label_text_font_size="7pt",
label_standoff=6, border_line_color=None, location=(0, 0))
p.add_layout(color_bar, 'right')
if use_notebook:
output_notebook()
show(p)
else:
export_png(p, filename)
print("save @ " + filename)
示例4: visualize_between_words
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def visualize_between_words(words, vecs, palette="Viridis256", filename="/notebooks/embedding/between-words.png",
use_notebook=False):
df_list = []
for word1_idx, word1 in enumerate(words):
for word2_idx, word2 in enumerate(words):
vec1 = vecs[word1_idx]
vec2 = vecs[word2_idx]
if np.any(vec1) and np.any(vec2):
score = cosine_similarity(X=[vec1], Y=[vec2])
df_list.append({'x': word1, 'y': word2, 'similarity': score[0][0]})
df = pd.DataFrame(df_list)
color_mapper = LinearColorMapper(palette=palette, low=1, high=0)
TOOLS = "hover,save,pan,box_zoom,reset,wheel_zoom"
p = figure(x_range=list(words), y_range=list(reversed(list(words))),
x_axis_location="above", plot_width=900, plot_height=900,
toolbar_location='below', tools=TOOLS,
tooltips=[('words', '@x @y'), ('similarity', '@similarity')])
p.grid.grid_line_color = None
p.axis.axis_line_color = None
p.axis.major_tick_line_color = None
p.axis.major_label_standoff = 0
p.xaxis.major_label_orientation = 3.14 / 3
p.rect(x="x", y="y", width=1, height=1,
source=df,
fill_color={'field': 'similarity', 'transform': color_mapper},
line_color=None)
color_bar = ColorBar(ticker=BasicTicker(desired_num_ticks=5),
color_mapper=color_mapper, major_label_text_font_size="7pt",
label_standoff=6, border_line_color=None, location=(0, 0))
p.add_layout(color_bar, 'right')
if use_notebook:
output_notebook()
show(p)
else:
export_png(p, filename)
print("save @ " + filename)
示例5: test_spikes_linear_color_op
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def test_spikes_linear_color_op(self):
spikes = Spikes([(0, 0, 0), (0, 1, 1), (0, 2, 2)],
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, LinearColorMapper)
self.assertEqual(cmapper.low, 0)
self.assertEqual(cmapper.high, 2)
self.assertEqual(cds.data['color'], np.array([0, 1, 2]))
self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
示例6: test_errorbars_linear_color_op
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def test_errorbars_linear_color_op(self):
errorbars = ErrorBars([(0, 0, 0.1, 0.2, 0), (0, 1, 0.2, 0.4, 1), (0, 2, 0.6, 1.2, 2)],
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, LinearColorMapper)
self.assertEqual(cmapper.low, 0)
self.assertEqual(cmapper.high, 2)
self.assertEqual(cds.data['color'], np.array([0, 1, 2]))
self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
示例7: test_box_whisker_linear_color_op
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def test_box_whisker_linear_color_op(self):
a = np.repeat(np.arange(5), 5)
b = np.repeat(np.arange(5), 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']
cmapper = plot.handles['box_color_color_mapper']
glyph = plot.handles['vbar_1_glyph']
self.assertEqual(source.data['box_color'], np.arange(5))
self.assertTrue(cmapper, LinearColorMapper)
self.assertEqual(cmapper.low, 0)
self.assertEqual(cmapper.high, 4)
self.assertEqual(glyph.fill_color, {'field': 'box_color', 'transform': cmapper})
示例8: test_vectorfield_linear_color_op
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def test_vectorfield_linear_color_op(self):
vectorfield = VectorField([(0, 0, 0, 1, 0), (0, 1, 0, 1, 1), (0, 2, 0, 1, 2)],
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, LinearColorMapper)
self.assertEqual(cmapper.low, 0)
self.assertEqual(cmapper.high, 2)
self.assertEqual(cds.data['color'], np.array([0, 1, 2, 0, 1, 2, 0, 1, 2]))
self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
示例9: test_violin_linear_color_op
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def test_violin_linear_color_op(self):
a = np.repeat(np.arange(5), 5)
b = np.repeat(np.arange(5), 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']
cmapper = plot.handles['violin_color_color_mapper']
glyph = plot.handles['patches_1_glyph']
self.assertEqual(source.data['violin_color'], np.arange(5))
self.assertTrue(cmapper, LinearColorMapper)
self.assertEqual(cmapper.low, 0)
self.assertEqual(cmapper.high, 4)
self.assertEqual(glyph.fill_color, {'field': 'violin_color', 'transform': cmapper})
示例10: test_point_linear_color_op
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def test_point_linear_color_op(self):
points = Points([(0, 0, 0), (0, 1, 1), (0, 2, 2)],
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, LinearColorMapper)
self.assertEqual(cmapper.low, 0)
self.assertEqual(cmapper.high, 2)
self.assertEqual(cds.data['color'], np.array([0, 1, 2]))
self.assertEqual(glyph.fill_color, {'field': 'color', 'transform': cmapper})
self.assertEqual(glyph.line_color, {'field': 'color', 'transform': cmapper})
示例11: test_label_linear_color_op
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def test_label_linear_color_op(self):
labels = Labels([(0, 0, 0), (0, 1, 1), (0, 2, 2)],
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, LinearColorMapper)
self.assertEqual(cmapper.low, 0)
self.assertEqual(cmapper.high, 2)
self.assertEqual(cds.data['text_color'], np.array([0, 1, 2]))
self.assertEqual(glyph.text_color, {'field': 'text_color', 'transform': cmapper})
示例12: test_bars_linear_color_op
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def test_bars_linear_color_op(self):
bars = Bars([(0, 0, 0), (0, 1, 1), (0, 2, 2)],
vdims=['y', 'color']).options(color='color')
plot = bokeh_renderer.get_plot(bars)
cds = plot.handles['cds']
glyph = plot.handles['glyph']
cmapper = plot.handles['color_color_mapper']
self.assertTrue(cmapper, LinearColorMapper)
self.assertEqual(cmapper.low, 0)
self.assertEqual(cmapper.high, 2)
self.assertEqual(cds.data['color'], np.array([0, 1, 2]))
self.assertEqual(glyph.fill_color, {'field': 'color', 'transform': cmapper})
self.assertEqual(glyph.line_color, 'black')
示例13: test_histogram_linear_color_op
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def test_histogram_linear_color_op(self):
histogram = Histogram([(0, 0, 0), (0, 1, 1), (0, 2, 2)],
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, LinearColorMapper)
self.assertEqual(cmapper.low, 0)
self.assertEqual(cmapper.high, 2)
self.assertEqual(cds.data['color'], np.array([0, 1, 2]))
self.assertEqual(glyph.fill_color, {'field': 'color', 'transform': cmapper})
self.assertEqual(glyph.line_color, 'black')
示例14: test_polygons_linear_color_op
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def test_polygons_linear_color_op(self):
polygons = Polygons([
{('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(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([7, 3]))
self.assertIsInstance(cmapper, LinearColorMapper)
self.assertEqual(cmapper.low, 3)
self.assertEqual(cmapper.high, 7)
示例15: _vtklut2bkcmap
# 需要导入模块: from bokeh import models [as 别名]
# 或者: from bokeh.models import LinearColorMapper [as 别名]
def _vtklut2bkcmap(self, lut, name):
table = lut.GetTable()
low, high = lut.GetTableRange()
rgba_arr = np.frombuffer(memoryview(table), dtype=np.uint8).reshape((-1, 4))
palette = [self._rgb2hex(*rgb) for rgb in rgba_arr[:,:3]]
return LinearColorMapper(low=low, high=high, name=name, palette=palette)