2016-12-02 22 views
0

私はボケを試しています。それは今のところかなり面白いです。しかし、私は完全にそれのハングアップを取得していません。私の目標は、シンプルでインタラクティブな散布図を作成することです。私は散布は私が決めることができますどこでウィジェットを大好きだcolors ボケのラベルと色のグリフ

  • に合わせて着色することにしたいnames
  • との散布図にラベルを付けたい

    1. 私は三つの主要な問題を抱えています色と名前が表示されている場合

    ここまでは私がこれまで行ってきたことです。私はLabelSetを使用しようとしましたが、私は立ち往生しています。どんな助けでも大歓迎です!

    # interactive widget bokeh figure 
    from bokeh.io import curdoc 
    from bokeh.layouts import row, widgetbox 
    from bokeh.models import ColumnDataSource 
    from bokeh.models.widgets import Slider, TextInput 
    from bokeh.plotting import figure 
    from bokeh.models import Range1d, LabelSet, Label 
    import numpy as np 
    
    # data 
    x = [-4, 3, 2, 4, 10, 11, -2, 6] 
    y = [-3, 2, 2, 9, 11, 12, -5, 6] 
    names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] 
    colors =['r', 'y', 'y', 'r', 'g', 'g', 'g', 'g'] 
    
    
    
    p = figure(plot_height=400, plot_width=400, title="a little interactive chart",   
           tools="crosshair,pan,reset,save,wheel_zoom", 
           x_range=[-10, 10], y_range=[-10, 10]) 
    
    labels = LabelSet(x='x', y='y', text='names', level='glyph', 
         x_offset=5, y_offset=5) 
    
    p.add_layout(labels) 
    
    
    p.circle(x, y, fill_color="red", line_color="red", size=6) 
    
    # Set up widgets 
    text = TextInput(title="title", value='a little interavtive chart') 
    
    # Set up callbacks 
    def update_title(attrname, old, new): 
        p.title.text = text.value 
    
    text.on_change('value', update_title) 
    
    # # Set up layouts and add to document 
    inputs = widgetbox(text, names) 
    
    curdoc().add_root(row(inputs, p, width=800)) 
    curdoc().title = "Sliders" 
    
  • 答えて

    1

    通常、LabelSetは、グリフレンダラと同じデータソースで構成することで使用します。私は、列データソースを共有するときはいつでも、それを明示的に作成するのが最善です。ここでレンダリングし、コードの更新バージョンがある:ウィジェットボックスはのみウィジェットモデルを含めることができるため

    # interactive widget bokeh figure 
    from bokeh.io import curdoc 
    from bokeh.layouts import row, widgetbox 
    from bokeh.models import ColumnDataSource, Range1d, LabelSet, Label 
    from bokeh.models.widgets import Slider, TextInput 
    from bokeh.plotting import figure 
    
    # data 
    x = [-4, 3, 2, 4, 10, 11, -2, 6] 
    y = [-3, 2, 2, 9, 11, 12, -5, 6] 
    names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] 
    colors =['r', 'y', 'y', 'r', 'g', 'g', 'g', 'g'] 
    
    # create a CDS by hand 
    source = ColumnDataSource(data=dict(x=x, y=y, names=names, colors=colors)) 
    
    p = figure(plot_height=400, plot_width=400, title="a little interactive chart", 
          tools="crosshair,pan,reset,save,wheel_zoom", 
          x_range=[-10, 10], y_range=[-10, 10]) 
    
    # pass the CDS here, and column names (not the arrays themselves) 
    p.circle('x', 'y', fill_color="red", line_color="red", size=6, source=source) 
    
    # pass the CDS here too 
    labels = LabelSet(x='x', y='y', text='names', level='glyph', 
         x_offset=5, y_offset=5, source=source) 
    p.add_layout(labels) 
    
    # Set up widgets 
    text = TextInput(title="title", value='a little interavtive chart') 
    
    # Set up callbacks 
    def update_title(attrname, old, new): 
        p.title.text = text.value 
    
    text.on_change('value', update_title) 
    
    # # Set up layouts and add to document 
    inputs = widgetbox(text) 
    
    curdoc().add_root(row(inputs, p, width=800)) 
    curdoc().title = "Sliders" 
    

    私もwidgetboxからnamesを削除しました。たぶんSelectウィジェットなどの名前を使用する予定ですか?

    +0

    うわー!ありがとうございました!はい、私は '選択 'を使用しようとしています。私はボケにはまったく新しいです。そのような初心者の質問を投稿して申し訳ありません!でも、しばらくそれをしなければならないでしょう... – Rachel

    +0

    'fill_color =" red "' 'colors = colors'を上書きしませんか?私の考えは、 'colors'を使ってグリフを個別に塗りつぶすことでしたか? – Rachel

    +0

    ああ...私は 'circle'で' colors'を渡す必要があります!ありがとうございました! – Rachel