示例#1
0
bokehcolors = [MM.colors.rgb2hex(cc) for cc in colors]
country_colors = [bokehcolors[numpy.where(classes==classlab)[0][0]] for classlab in classlabs]

# bokeh interactive plot
source = ColumnDataSource(data=dict(
        x=data_x,
        y=data_y,
        name=countries,
        info = [[df['Culture'].iloc[ind], df['Language'].iloc[ind], df['Genre_Album'].iloc[ind]] for ind in range(n_samples)],
        url=numpy.array(df['songurls_Album'].get_values(), dtype=str),
        color = country_colors
    ))
TOOLS="wheel_zoom,box_zoom,pan,reset,save,resize"
    
p = figure(tools=TOOLS, plot_width=1200, title="")
r1 = p.patches(pp_x, pp_y, fill_color='white', line_width=0.4, line_color='grey')
r2 = p.circle_cross('x','y', size=4, line_color=country_colors, source=source) 
r3 = p.multi_line(xs=line_x, ys=line_y, alpha=0.5, color='grey', line_width=0.2)

# some interactive functionality on mouse click and mouse over
callback = CustomJS(args=dict(r2=r2), code="""
        var inds = cb_obj.get('selected')['1d'].indices;
        var d1 = cb_obj.get('data');
        url = d1['url'][inds[0]];
        if (url){
            window.open(url);}""")
hover_tooltips = """
    <div>
        <div>
            <span style="font-size: 17px; font-weight: bold;">@name</span>
        </div>