Shaded and stairs
Filled areas and step plots. Three items cover the common “area” shapes:
plot_shaded_between fills the region between two y series (a confidence /
envelope band), plot_shaded fills between a series and a horizontal baseline,
and plot_stairs draws a sample-and-hold step line. next_fill_style colors
the next filled item, just as next_line_style colors the next line.
plot(BAND, (title = "confidence band", size = float2(-1.0f, 420.0f), flags = ImPlotFlags.None)) {
setup_axes("x", "value")
setup_axes_limits(0.0lf, double(N), -1.6lf, 1.6lf)
next_fill_style(float4(0.30f, 0.65f, 1.00f, 0.35f))
plot_shaded_between("band", g_x, g_lo, g_hi) // fill between two curves
next_line_style(float4(0.20f, 0.55f, 1.00f, 1.00f), 2.0f)
plot_line("mean", g_x, g_mid)
}
Source: examples/tutorial/shaded_and_stairs.das.
1options gen2
2options _comment_hygiene = true
3
4require imgui/imgui_harness
5require imgui/imgui_containers_builtin
6require imgui/imgui_widgets_builtin
7require imgui/imgui_implot_boost_v2
8require implot
9require math
10
11// =============================================================================
12// TUTORIAL: shaded_and_stairs — filled areas and step plots.
13//
14// plot_shaded_between(id, xs, lo, hi) — fill the area BETWEEN two y series
15// (a confidence / envelope band).
16// plot_shaded(id, values, yref) — fill the area between a series and a
17// horizontal baseline yref (default 0).
18// plot_stairs(id, values) — a step plot (sample-and-hold).
19// next_fill_style / next_line_style — color the NEXT shaded / line item.
20//
21// STANDALONE: daslang.exe modules/dasImguiImplot/examples/tutorial/shaded_and_stairs.das
22// LIVE: daslang-live modules/dasImguiImplot/examples/tutorial/shaded_and_stairs.das
23// =============================================================================
24
25let N = 120
26let STEPS = 16
27
28var g_ctx : ImPlotContext?
29var g_x : array<double> // shared x for the band
30var g_mid : array<double> // mean curve
31var g_lo : array<double> // band lower edge
32var g_hi : array<double> // band upper edge
33var g_steps : array<double> // coarse step levels
34
35[export]
36def init() {
37 harness_init("dasImguiImplot — shaded_and_stairs", 1280, 860)
38 g_ctx = implot::CreateContext()
39 g_x <- [for (i in range(N)); double(i)]
40 g_mid <- [for (i in range(N)); double(sin(float(i) * 0.08f))]
41 // A band whose width grows with x, to show plot_shaded_between clearly.
42 g_lo <- [for (i in range(N)); double(sin(float(i) * 0.08f)) - (0.15lf + double(i) / double(N) * 0.4lf)]
43 g_hi <- [for (i in range(N)); double(sin(float(i) * 0.08f)) + (0.15lf + double(i) / double(N) * 0.4lf)]
44 g_steps <- [for (i in range(STEPS)); double((i * 7) % 5)]
45}
46
47[export]
48def update() {
49 if (!harness_begin_frame()) return
50 harness_new_frame()
51
52 SetNextWindowPos(float2(20.0, 20.0), ImGuiCond.Always)
53 SetNextWindowSize(float2(1240.0, 820.0), ImGuiCond.Always)
54 window(PLOT_WIN, (text = "shaded & stairs", closable = false,
55 flags = ImGuiWindowFlags.None)) {
56 text("plot_shaded_between draws a band; plot_shaded fills to a baseline; plot_stairs steps.")
57 // A confidence band (area between lo and hi) with the mean line on top.
58 plot(BAND, (title = "confidence band", size = float2(-1.0f, 420.0f),
59 flags = ImPlotFlags.None)) {
60 setup_axes("x", "value")
61 setup_axes_limits(0.0lf, double(N), -1.6lf, 1.6lf)
62 next_fill_style(float4(0.30f, 0.65f, 1.00f, 0.35f))
63 plot_shaded_between("band", g_x, g_lo, g_hi)
64 next_line_style(float4(0.20f, 0.55f, 1.00f, 1.00f), 2.0f)
65 plot_line("mean", g_x, g_mid)
66 }
67 // A step series with the area under it filled.
68 plot(STAIRS, (title = "stairs + fill", size = float2(-1.0f, 300.0f),
69 flags = ImPlotFlags.None)) {
70 setup_axes("bucket", "level")
71 setup_axes_limits(0.0lf, double(STEPS), 0.0lf, 5.0lf)
72 next_fill_style(float4(1.00f, 0.70f, 0.25f, 0.30f))
73 plot_shaded("fill", g_steps)
74 next_line_style(float4(1.00f, 0.55f, 0.10f, 1.00f), 2.0f)
75 plot_stairs("steps", g_steps)
76 }
77 }
78
79 harness_end_frame()
80}
81
82[export]
83def shutdown() {
84 if (g_ctx != null) {
85 DestroyContext(g_ctx)
86 }
87 harness_shutdown()
88}
89
90[export]
91def main() {
92 init()
93 while (!exit_requested()) {
94 update()
95 }
96 shutdown()
97}
Walkthrough
A guided tour of the filled-area items. The cursor traces the confidence band
left to right — the fill widens toward the right, the way an interval grows — then
drops to the step plot below, where plot_stairs holds each sample and
plot_shaded fills the area beneath the steps down to the baseline. There is no
interaction to teach beyond the shapes; the recording self-verifies that both
plots render at every beat, so a dead frame or a missing chart fails at teardown.
Bands between two series
plot_shaded_between(id, xs, ys1, ys2) fills the vertical region between
ys1 and ys2 at each x. The example builds a band whose half-width grows
with x, so the fill is visibly wider on the right — a typical way to show a
confidence interval around the mean line drawn on top of it.
Fill to a baseline
plot_shaded(id, values, yref) fills between values and the horizontal line
y = yref (default 0). In the second plot it fills the area under the step
series; pass a non-zero yref to fill toward a different baseline.
Step plots
plot_stairs(id, values) connects samples with horizontal-then-vertical
segments instead of straight lines — the right shape for piecewise-constant data
(counts per bucket, a held signal).