whisker#
一个标记图,显示汽车类型和高速公路 MPG 之间的关系,数据来自 autompg 样本数据。此示例演示了如何使用须线在图中显示分位数范围。
详情
- 样本数据:
- Bokeh API:
bokeh.models.ColumnDataSource
,bokeh.models.Whisker
,bokeh.transform.factor_cmap
,bokeh.transform.jitter
,figure.scatter
- 更多信息:
- 关键词:
whisker,jitter,scatter,error
from bokeh.models import ColumnDataSource, Whisker
from bokeh.plotting import figure, show
from bokeh.sampledata.autompg2 import autompg2 as df
from bokeh.transform import factor_cmap, jitter
classes = list(sorted(df["class"].unique()))
p = figure(height=400, x_range=classes, background_fill_color="#efefef",
title="Car class vs HWY mpg with quantile ranges")
p.xgrid.grid_line_color = None
g = df.groupby("class")
upper = g.hwy.quantile(0.80)
lower = g.hwy.quantile(0.20)
source = ColumnDataSource(data=dict(base=classes, upper=upper, lower=lower))
error = Whisker(base="base", upper="upper", lower="lower", source=source,
level="annotation", line_width=2)
error.upper_head.size=20
error.lower_head.size=20
p.add_layout(error)
p.scatter(jitter("class", 0.3, range=p.x_range), "hwy", source=df,
alpha=0.5, size=13, line_color="white",
color=factor_cmap("class", "Light7", classes))
show(p)