从bokeh 1.0开始,可以使用
marker_map
和CDS过滤器:
from bokeh.plotting import figure, show, output_file
from bokeh.sampledata.iris import flowers
from bokeh.transform import factor_cmap, factor_mark
SPECIES = ['setosa', 'versicolor', 'virginica']
MARKERS = ['hex', 'circle_x', 'triangle']
p = figure(title = "Iris Morphology", background_fill_color="#fafafa")
p.xaxis.axis_label = 'Petal Length'
p.yaxis.axis_label = 'Sepal Width'
p.scatter("petal_length", "sepal_width", source=flowers, legend="species",
fill_alpha=0.4, size=12,
marker=factor_mark('species', MARKERS, SPECIES),
color=factor_cmap('species', 'Category10_3', SPECIES))
show(p)
旧答案
从博克开始
0.13.0
将标记类型直接从数据参数化仍然是一个开放的功能请求:
#5884
Create Marker class that encompasses all markers and allow specific marker type to be specified from data
在实现之前,你最好利用
CDSView
models
要在多个glyph方法中拆分单个数据集,请执行以下操作:
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, CDSView, GroupFilter
from bokeh.sampledata.iris import flowers
source = ColumnDataSource(flowers)
setosa = CDSView(source=source, filters=[GroupFilter(column_name='species', group='setosa')])
versicolor = CDSView(source=source, filters=[GroupFilter(column_name='species', group='versicolor')])
virginica = CDSView(source=source, filters=[GroupFilter(column_name='species', group='virginica')])
p = figure()
p.circle(x='petal_length', y='petal_width', source=source, view=setosa,
size=10, color='red', alpha=0.6, legend='setosa')
p.square(x='petal_length', y='petal_width', source=source, view=versicolor,
size=10, color='green', alpha=0.6, legend='versicolor')
p.triangle(x='petal_length', y='petal_width', source=source, view=virginica,
size=10, color='blue', alpha=0.6, legend='virginica')
p.legend.location = "top_left"
show(p)