Python bokeh.models.LinearColorMapper() Examples
The following are 19
code examples of bokeh.models.LinearColorMapper().
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: visualize_utils.py From embedding with MIT License | 6 votes |
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)
Example #2
Source File: visualize_utils.py From embedding with MIT License | 6 votes |
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)
Example #3
Source File: testvectorfieldplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
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})
Example #4
Source File: configurator_footprint.py From CAVE with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _plot_contour(self, p, contour_data, x_range, y_range): """Plot contour data. Parameters ---------- p: bokeh.plotting.figure figure to be drawn upon contour_data: Dict[str -> np.array] dict from labels to array with contour data x_range: List[float, float] min and max of x-axis y_range: List[float, float] min and max of y-axis Returns ------- handles: dict[str -> tuple(ImageGlyph, tuple(float, float))] mapping from label to image glyph and min/max-tuple """ unique = np.unique(np.concatenate([contour_data[label][2] for label in contour_data.keys()])) color_mapper = LinearColorMapper(palette="Viridis256", low=np.min(unique), high=np.max(unique)) handles = {} default_label = 'combined' if 'combined' in contour_data.keys() else list(contour_data.keys())[0] for label, data in contour_data.items(): unique = np.unique(contour_data[label][2]) handles[label] = (p.image(image=contour_data[label], x=x_range[0], y=y_range[0], dw=x_range[1] - x_range[0], dh=y_range[1] - y_range[0], color_mapper=color_mapper), (np.min(unique), np.max(unique))) if not label == default_label and len(contour_data) > 1: handles[label][0].visible = False color_bar = ColorBar(color_mapper=color_mapper, ticker=BasicTicker(desired_num_ticks=15), label_standoff=12, border_line_color=None, location=(0, 0)) color_bar.major_label_text_font_size = '12pt' p.add_layout(color_bar, 'right') return handles, color_mapper
Example #5
Source File: NeoPredViz.py From NeoPredPipe with GNU Lesser General Public License v3.0 | 5 votes |
def HeatTable(self): ready = {} for item in self.sharedCount: ready.update({ (item.split(',')[0],item.split(',')[1]): self.sharedCount[item] }) k = np.array([item for item in ready]) v = np.array([ready[item] for item in ready]) unq_keys, key_idx = np.unique(k, return_inverse=True) key_idx = key_idx.reshape(-1, 2) n = len(unq_keys) adj = np.zeros((n, n), dtype=v.dtype) adj[key_idx[:, 0], key_idx[:, 1]] = v adj += adj.T adj = adj.astype(float) for i in range(0,adj.shape[0]): for k in range(0,adj.shape[1]): if k<=i: adj[i,k]=np.nan dfout = pd.DataFrame(data=np.log10(adj+0.01),index = unq_keys, columns = unq_keys) dfout.index.name = 'Sam1' dfout.columns.name = 'Sam2' df = pd.DataFrame(dfout.stack(), columns=['Neoantigens']).reset_index() source = ColumnDataSource(df) import bokeh.palettes as p colors = p.Plasma256 mapper = LinearColorMapper(palette=colors, low=df.Neoantigens.min(), high=df.Neoantigens.max()) p = figure(title = "log10( Shared Neoantigens )", plot_height=400, plot_width=400, x_range=list(dfout.index), y_range=list(reversed(dfout.columns)), toolbar_location=None, tools="", x_axis_location="below") p.grid.grid_line_color = None p.axis.axis_line_color = None p.axis.major_tick_line_color = None p.axis.major_label_text_font_size = "5pt" p.axis.major_label_standoff = 0 p.xaxis.major_label_orientation = np.pi / 3 p.rect(x='Sam1',y='Sam2', source=source, width=1, height=1, fill_color={'field':'Neoantigens','transform':mapper}, line_color=None) color_bar = ColorBar(color_mapper=mapper, location=(0, 0), ticker=BasicTicker(desired_num_ticks=int(len(colors)/10))) p.add_layout(color_bar, 'right') return(p)
Example #6
Source File: vtk.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #7
Source File: testpathplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #8
Source File: testhistogramplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
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')
Example #9
Source File: testbarplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
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')
Example #10
Source File: testlabels.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
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})
Example #11
Source File: testpointplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
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})
Example #12
Source File: testviolinplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
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})
Example #13
Source File: testboxwhiskerplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
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})
Example #14
Source File: testerrorbarplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
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})
Example #15
Source File: testspikesplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
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})
Example #16
Source File: visualize_utils.py From embedding with MIT License | 5 votes |
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)
Example #17
Source File: visualize_utils.py From embedding with MIT License | 5 votes |
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)
Example #18
Source File: plot.py From arlpy with BSD 3-Clause "New" or "Revised" License | 4 votes |
def image(img, x=None, y=None, colormap='Plasma256', clim=None, clabel=None, title=None, xlabel=None, ylabel=None, xlim=None, ylim=None, xtype='auto', ytype='auto', width=None, height=None, hold=False, interactive=None): """Plot a heatmap of 2D scalar data. :param img: 2D image data :param x: x-axis range for image data (min, max) :param y: y-axis range for image data (min, max) :param colormap: named color palette or Bokeh ColorMapper (see `Bokeh palettes <https://bokeh.pydata.org/en/latest/docs/reference/palettes.html>`_) :param clim: color axis limits (min, max) :param clabel: color axis label :param title: figure title :param xlabel: x-axis label :param ylabel: y-axis label :param xlim: x-axis limits (min, max) :param ylim: y-axis limits (min, max) :param xtype: x-axis type ('auto', 'linear', 'log', etc) :param ytype: y-axis type ('auto', 'linear', 'log', etc) :param width: figure width in pixels :param height: figure height in pixels :param interactive: enable interactive tools (pan, zoom, etc) for plot :param hold: if set to True, output is not plotted immediately, but combined with the next plot >>> import arlpy.plot >>> import numpy as np >>> arlpy.plot.image(np.random.normal(size=(100,100)), colormap='Inferno256') """ global _figure if x is None: x = (0, img.shape[1]-1) if y is None: y = (0, img.shape[0]-1) if xlim is None: xlim = x if ylim is None: ylim = y if _figure is None: _figure = _new_figure(title, width, height, xlabel, ylabel, xlim, ylim, xtype, ytype, interactive) if clim is None: clim = [_np.amin(img), _np.amax(img)] if not isinstance(colormap, _bmodels.ColorMapper): colormap = _bmodels.LinearColorMapper(palette=colormap, low=clim[0], high=clim[1]) _figure.image([img], x=x[0], y=y[0], dw=x[-1]-x[0], dh=y[-1]-y[0], color_mapper=colormap) cbar = _bmodels.ColorBar(color_mapper=colormap, location=(0,0), title=clabel) _figure.add_layout(cbar, 'right') if not hold and not _hold: _show(_figure) _figure = None
Example #19
Source File: visualize_utils.py From embedding with MIT License | 4 votes |
def visualize_homonym(homonym, tokenized_sentences, vecs, model_name, palette="Viridis256", filename="/notebooks/embedding/homonym.png", use_notebook=False): # process sentences token_list, processed_sentences = [], [] for tokens in tokenized_sentences: token_list.extend(tokens) sentence = [] for token in tokens: if model_name == "bert": processed_token = token.replace("##", "") else: processed_token = token if token == homonym: processed_token = "\"" + processed_token + "\"" sentence.append(processed_token) processed_sentences.append(' '.join(sentence)) # dimension reduction tsne = TSNE(n_components=2) tsne_results = tsne.fit_transform(vecs[1:]) # only plot the word representation of interest interest_vecs, idx = np.zeros((len(tokenized_sentences), 2)), 0 for word, vec in zip(token_list, tsne_results): if word == homonym: interest_vecs[idx] = vec idx += 1 df = pd.DataFrame(columns=['x', 'y', 'annotation']) df['x'], df['y'], df['annotation'] = interest_vecs[:, 0], interest_vecs[:, 1], processed_sentences source = ColumnDataSource(ColumnDataSource.from_df(df)) labels = LabelSet(x="x", y="y", text="annotation", 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)