误差棒与填充带#
用途与概念#
errorbar 在采样点绘制 xerr/yerr 不确定度,band 在 x 对应的 lower/upper 之间填充。误差是数据单位,cap_size 和线宽是物理长度。
最小完整示例#
此文件包含画布及必要定义,可直接运行 laymesh validate 或 laymesh render,不依赖前文未声明的变量。
# Minimal complete example: plot.errorbarpage=canvas(size=(100mm,75mm),background="#ffffff")p=plot(size=(86mm,62mm),x=axis(range=(0,4)),y=axis(range=(0,5)))p.errorbar(x=[1,2,3],y=[1,3,2],yerr=[0.2,0.4,0.3])page.add(p,offset=(7mm,6mm))# Minimal complete example: plot.errorbarpage=canvas(size=(100mm,75mm),background="#ffffff")p=plot(size=(86mm,62mm),x=axis(range=(0,4)),y=axis(range=(0,5)))p.errorbar(x=[1,2,3],y=[1,3,2],yerr=[0.2,0.4,0.3])page.add(p,offset=(7mm,6mm))预览
背景
依赖文件
examples/manual/plot-errorbar.lay
参数与默认行为#
裸几何长度使用画布单位,裸字号和描边宽度使用 pt。显式调用参数优先于继承和主题默认值;下面的接口参考逐项列出允许类型、可选值与默认来源。
组合用法#
同一实验数据可组合半透明 band、中心折线及点误差。误差可对称或分别指定上下误差;上下界须与采样位置对应。
page = canvas(size=(180 mm, 82 mm), background="#ffffff")d = table(src="results.csv")style = plot_style(font_family="DejaVu Sans", font_size=8 pt, line_width=0.6 pt)p = plot(size=(80 mm, 65 mm), x=axis(label="Time (s)"), y=axis(label="Intensity"), style=style)p.band(x=d["time"], lower=d["lower"], upper=d["upper"], color="#0072B2")p.line(x=d["time"], y=d["signal"], color="#0072B2", label="Experiment")p.scatter(x=d["time"], y=d["signal"], color="#0072B2", marker_size=3 pt)p.errorbar(x=d["time"], y=d["signal"], yerr=d["error"], color="#0072B2")p.hline(y=2, color="#777777", line_dash=[2 pt, 2 pt], label="Reference")p.legend(position= top_left)left = page.add(p, target=page.top_left, offset=(7 mm, 6 mm))h = plot(size=(80 mm, 65 mm), x=axis(label="x"), y=axis(label="y"), style=style)heat = h.heatmap(z=[[1,2,3,4],[2,4,6,5],[3,6,9,6],[4,5,6,4]], extent=(0,4,0,4), origin= lower, cmap="viridis")h.colorbar(heat, label="Value")page = canvas(size=(180 mm, 82 mm), background="#ffffff")d = table(src="results.csv")style = plot_style(font_family="DejaVu Sans", font_size=8 pt, line_width=0.6 pt)p = plot(size=(80 mm, 65 mm), x=axis(label="Time (s)"), y=axis(label="Intensity"), style=style)p.band(x=d["time"], lower=d["lower"], upper=d["upper"], color="#0072B2")p.line(x=d["time"], y=d["signal"], color="#0072B2", label="Experiment")p.scatter(x=d["time"], y=d["signal"], color="#0072B2", marker_size=3 pt)p.errorbar(x=d["time"], y=d["signal"], yerr=d["error"], color="#0072B2")p.hline(y=2, color="#777777", line_dash=[2 pt, 2 pt], label="Reference")p.legend(position= top_left)left = page.add(p, target=page.top_left, offset=(7 mm, 6 mm))h = plot(size=(80 mm, 65 mm), x=axis(label="x"), y=axis(label="y"), style=style)heat = h.heatmap(z=[[1,2,3,4],[2,4,6,5],[3,6,9,6],[4,5,6,4]], extent=(0,4,0,4), origin= lower, cmap="viridis")h.colorbar(heat, label="Value")right = page.add(h, target=left.top_right, offset=(6 mm, 0 mm))page.add(text(content="(a)", font_family="DejaVu Sans", font_size=9 pt), target=left.top_left)page.add(text(content="(b)", font_family="DejaVu Sans", font_size=9 pt), target=right.top_left)time,signal,error,lower,upper0,0.4,0.12,0.28,0.521,1.3,0.18,1.12,1.482,1.9,0.15,1.75,2.053,1.5,0.20,1.30,1.704,2.7,0.22,2.48,2.925,3.1,0.16,2.94,3.26预览
背景
依赖文件
examples/plot/results.csvexamples/plot/scientific.lay
常见错误与限制#
误差不能为负,数组长度必须相同。断轴或投影裁剪不会制造新的误差端帽;缺失输入保留诊断。不要把上下界误传成误差幅度。
逐项功能说明#
plot-errorbar#
向图表添加误差棒。xerr、yerr 支持对称误差或分别提供上下界误差;cap_size 设置端帽的物理长度。
返回:图层句柄,可用于共享图例。
plot-band#
填充带图层:向当前图表添加数据,通过物理样式参数控制外观,并使用命名轴参数选择数据映射。
返回:图层句柄,可用于共享图例。
详细行为与补充示例#
参数#
| 参数 | 用途 | 默认或要求 |
|---|---|---|
yerr / xerr |
误差范围 | 与观测匹配 |
lower / upper |
填充上下界 | 与 x 等长 |
常见用法#
误差棒表达每个观测的不确定度;band 用 lower/upper 表达连续区间。示例左侧同时包含折线、散点、填充带、误差棒和参考线,右侧展示热图。

