2017-12-05 9 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 (매개 변수 vmaxvmin)과 같이 빨간색에서 파란색 (-1에서 1)까지입니다.

쉬운 방법이 있습니까?

답변

1

Bokeh에는 값을 색상에 매핑 한 다음 플롯 글리프에 적용하는 inbuilt 기능이 있습니다.

각 지점의 색상 목록을 만들고이 기능을 사용하지 않으려는 경우이 지점을 전달할 수 있습니다.

간단한 예를 아래 참조 :

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)