2017-11-30 11 views
0

質問を更新:bokehのvbarは非選択色とアルファをサポートしていませんか?

バープロットで特定の種を選択するには、選択されていないバーは色が変わりますか? 各バーの上にテキストを表示するにはどうすればよいですか?

from bokeh.sampledata.iris import flowers 
from bokeh.plotting import figure, output_file, show 
from bokeh.models import ColumnDataSource, CategoricalColorMapper 
from bokeh.layouts import column, row 

#color mapper to color data by species 
mapper = CategoricalColorMapper(factors = ['setosa','versicolor', 'virginica'],\ 
           palette = ['green', 'blue', 'red']) 


output_file("plots.html") 

#group by species and plot barplot for count 
species = flowers.groupby('species') 

source = ColumnDataSource(species) 

p = figure(plot_width = 800, plot_height = 400, title = 'Count by Species', \ 
      x_range = source.data['species'], tools = 'box_select') 

p.vbar(x = 'species', top = 'petal_length_count', width = 0.8, source = source,\ 
     nonselection_fill_color = 'gray', nonselection_fill_alpha = 0.2,\ 
     color = {'field': 'species', 'transform': mapper}) 
show(p) 

答えて

2

最初に、別のSO投稿の無関係な質問をしてみてください。


ヒットテストと選択が最近までvbarhbarのために実装されていませんでした。あなたが欠けているとして、最近0.12.11リリースを使用して、あなたのコードは動作します。

labels = LabelSet(x='species', y='petal_count_length', text='some_column', 
        x_offset=5, y_offset=5, source=source) 

p.add_layout(labels) 

enter image description here

を各バーのラベルについては、次のようなdemonstrated in the User's Guideものとして、LabelSetアノテーションを使用したいですリンクの質問があまりにも曖昧です。私はあなたが達成しようとしていることについて、より多くの情報と説明で新しいSOの質問を開くことを提案します。

+0

あなたの答えをありがとう!最初の2つの質問を解決して解決します。私はあなたの提案でコードを更新し、リンクされたグラフについて別の質問をここに:https://stackoverflow.com/questions/47579840/how-to-link-vbar-with-circle-plots-using-bokeh –

関連する問題