代码之家  ›  专栏  ›  技术社区  ›  0x90 Salvador Dali

如何用描述和独特的填充颜色数组在Bokeh上绘制散点图?

  •  0
  • 0x90 Salvador Dali  · 技术社区  · 6 年前

    我试了下面的方法,但是颜色仍然是蓝色的。

    from bokeh.plotting import figure, show, output_file, ColumnDataSource
    
    
    TOOLS="hover,crosshair,pan,wheel_zoom,zoom_in,zoom_out,box_zoom,undo,redo,reset,tap,save,box_select,poly_select,lasso_select,"
    
    
    
    source = ColumnDataSource(data=dict(
            x=[1,2,3,4,5,6], 
            y=[2,2,4,5,6,7],
            desc=['type1', 'type1', 'type2','type2','type1','type1'],
            fill_color=['green','grey','grey','red','red','red'], 
            #fill_alpha=0.6, 
            #line_color=None
        ))
    
    TOOLTIPS = [
            ("index", "$index"),
            ("(x,y)", "($x, $y)"),
            ("desc", "@desc"),
            ("fill_color", "@fill_color")]
    
    p = figure(tools=TOOLS,  plot_width=1000, tooltips=TOOLTIPS)
    p.scatter(x='x',y='y', source=source)
    output_file("color_scatter.html", title="color_scatter.py example")
    show(p)  # open a browser
    

    enter image description here

    我怎么能同时拥有标签和独特的颜色在一个博克的散射?

    1 回复  |  直到 6 年前
        1
  •  1
  •   bigreddot    6 年前

    你没有告诉我 scatter 要使用数据源中的颜色数据,请执行以下操作:

    p.scatter(x='x', y='y', fill_color='fill_color', source=source)