Skip to content

Instantly share code, notes, and snippets.

@orm011
Created August 30, 2021 03:43
Show Gist options
  • Save orm011/0aea6984a419c334a3178d14ce9d16f8 to your computer and use it in GitHub Desktop.
Save orm011/0aea6984a419c334a3178d14ce9d16f8 to your computer and use it in GitHub Desktop.
plot_figure = figure(
title='embedding plot',
plot_width=700,
plot_height=400,
tools=('pan, wheel_zoom, reset, tap, box_select'),
output_backend="webgl"
)
color_col = 'curr_label'
cids = class_names#db_df[color_col].unique() # really should be class
# cids = (["-1"] if "-1" in cids else []) + [x for x in np.random.permutation(cids) if x != "-1"]
# colors = Magma256[::len(Magma256)//len(cids)][:len(cids)]
# color_mapping = CategoricalColorMapper(factors=cids,palette=colors)
# clr = dict(field='color_col', transform=color_mapping)
clr = factor_cmap(color_col, palette=Category20[len(cids)], factors=cids, )
db_scatter = plot_figure.circle(x='x', y='y', radius=4, radius_units='screen', fill_alpha=.8,
legend_field='orig_label',color=clr, source=db_cds)
selected_circle = Circle(fill_alpha=1., fill_color=clr, line_alpha=1.)
nonselected_circle = Circle(fill_alpha=1., fill_color=clr, line_alpha=0.)
db_scatter.selection_glyph = selected_circle
db_scatter.nonselection_glyph = nonselected_circle
plot_figure.add_tools(HoverTool(tooltips="""
<div style="border: 1px solid;border-radius: 5px;padding:2px;margin:2px">
<div>
<img src="@image_url" style='float: center; margin: 5px 5px 5px 5px; padding:1px; width:100%; height:100%; object-fit: contain'/>
</div>
<div>
<span style='font-size: 16px; color: #224499'>Label: @curr_label</span>
<br/>
<span style='font-size: 16px; color: #224499'>Orig. Label: @orig_label</span>
<br/>
<span style='font-size: 16px; color: #224499'>Id: @index</span>
</div>
</div>
""", renderers=[db_scatter]))
from bokeh.models import WheelZoomTool
plot_figure.toolbar.active_scroll = plot_figure.select_one(WheelZoomTool)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment