我正在尝试与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)
Run Code Online (Sandbox Code Playgroud)
理想情况下,随着数据接近其最大值/最小值,我想用更强的颜色进行着色y。例如,从红色到蓝色(-1到1),就像在热图中一样(参数vmax和vmin)。
有一个简单的方法吗?
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)
Run Code Online (Sandbox Code Playgroud)