2017-12-05 66 views
1

Bokehで散布図を作ろうとしています。たとえば、次のデータがyの最大/最小値に近づくようグラデーションカラーのBokeh散布図

from bokeh.plotting import figure, show, output_notebook 

TOOLS='pan,wheel_zoom,box_zoom,reset' 
p = figure(tools=TOOLS) 

p.scatter(x=somedata.x, y=somedata.y) 

理想的には、私は、より強い強度で着色したいです。たとえば、heatmap(パラメータvmaxおよびvmin)のように、赤から青(-1から1)のように指定します。

簡単な方法はありますか?

答えて

1

Bokehには、値を色にマッピングしてプロットグリフに適用するための組み込み機能があります。

代わりに、各ポイントの色のリストを作成し、この機能を使用しない場合はこれらを渡すこともできます。

簡単な例以下を参照してください。

import numpy as np 
from bokeh.plotting import figure, show 
from bokeh.models import ColumnDataSource, LinearColorMapper 


TOOLS='pan,wheel_zoom,box_zoom,reset' 
p = figure(tools=TOOLS) 

x = np.linspace(-10,10,200) 
y = -x**2 

data_source = ColumnDataSource({'x':x,'y':y}) 

color_mapper = LinearColorMapper(palette='Magma256', low=min(y), high=max(y)) 

# specify that we want to map the colors to the y values, 
# this could be replaced with a list of colors 
p.scatter(x,y,color={'field': 'y', 'transform': color_mapper}) 

show(p)