如何在Bokeh中使用z列的分类数据制作散点图?像matplotlib'彩虹'颜色图

时间:2019-06-19 15:15:50

标签: python-3.x

from bokeh.plotting import figure, show, output_file, output_notebook
from bokeh.models import ColumnDataSource, ColorBar
from bokeh.palettes import Spectral6
from bokeh.transform import linear_cmap

output_file(“ styling_linear_mappers.html”,title =“ styling_linear_mappers.py示例”)

x = [1,2,3,4,5,7,8,9,10]
y = [1,2,3,4,5,7,8,9,10]
z = [1,2,3,4,5,7,8,9,10]

使用列源的字段名称

mapper = linear_cmap(field_name='z', palette=Spectral6 ,low=min(z) ,high=max(z))

source = ColumnDataSource(dict(x=x,y=y))

p = figure(plot_width=300, plot_height=300, title="Linear Color Map Based on Y")

p.circle(x=x, y=y, line_color=mapper,color=mapper, fill_alpha=1, size=12)

color_bar = ColorBar(color_mapper=mapper['transform'], width=8,  location=(0,0))

p.add_layout(color_bar, 'right')

output_notebook()
show(p)

0 个答案:

没有答案