我正在尝试用散景制作一个散点图.例如:
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)
理想情况下,当数据接近y的最大/最小值时,我希望以更强的强度着色.例如,从红色到蓝色(-1到1),就像在heatmap(参数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)
标签:python,plot,bokeh
来源: https://codeday.me/bug/0828/1749371.html