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
 2
 3require imgui/imgui_harness
 4require imgui/imgui_containers_builtin
 5require imgui/imgui_widgets_builtin
 6require imgui/imgui_implot_boost_v2
 7require implot
 8require math
 9
10// =============================================================================
11// TUTORIAL: shaded_and_stairs — filled areas and step plots.
12//
13//   plot_shaded_between(id, xs, lo, hi)  — fill the area BETWEEN two y series
14//                                          (a confidence / envelope band).
15//   plot_shaded(id, values, yref)        — fill the area between a series and a
16//                                          horizontal baseline yref (default 0).
17//   plot_stairs(id, values)              — a step plot (sample-and-hold).
18//   next_fill_style / next_line_style    — color the NEXT shaded / line item.
19//
20// STANDALONE: daslang.exe modules/dasImguiImplot/examples/tutorial/shaded_and_stairs.das
21// LIVE:       daslang-live modules/dasImguiImplot/examples/tutorial/shaded_and_stairs.das
22// =============================================================================
23
24let N = 120
25let STEPS = 16
26
27var g_ctx : ImPlotContext?
28var g_x : array<double>        // shared x for the band
29var g_mid : array<double>      // mean curve
30var g_lo : array<double>       // band lower edge
31var g_hi : array<double>       // band upper edge
32var g_steps : array<double>    // coarse step levels
33
34[export]
35def init() {
36    harness_init("dasImguiImplot — shaded_and_stairs", 1280, 860)
37    g_ctx = implot::CreateContext()
38    g_x   <- [for (i in range(N)); double(i)]
39    g_mid <- [for (i in range(N)); double(sin(float(i) * 0.08f))]
40    // A band whose width grows with x, to show plot_shaded_between clearly.
41    g_lo  <- [for (i in range(N)); double(sin(float(i) * 0.08f)) - (0.15lf + double(i) / double(N) * 0.4lf)]
42    g_hi  <- [for (i in range(N)); double(sin(float(i) * 0.08f)) + (0.15lf + double(i) / double(N) * 0.4lf)]
43    g_steps <- [for (i in range(STEPS)); double((i * 7) % 5)]
44}
45
46[export]
47def update() {
48    if (!harness_begin_frame()) return
49    harness_new_frame()
50
51    SetNextWindowPos(float2(20.0, 20.0), ImGuiCond.Always)
52    SetNextWindowSize(float2(1240.0, 820.0), ImGuiCond.Always)
53    window(PLOT_WIN, (text = "shaded & stairs", closable = false,
54                      flags = ImGuiWindowFlags.None)) {
55        text("plot_shaded_between draws a band; plot_shaded fills to a baseline; plot_stairs steps.")
56        // A confidence band (area between lo and hi) with the mean line on top.
57        plot(BAND, (title = "confidence band", size = float2(-1.0f, 420.0f),
58                    flags = ImPlotFlags.None)) {
59            setup_axes("x", "value")
60            setup_axes_limits(0.0lf, double(N), -1.6lf, 1.6lf)
61            next_fill_style(float4(0.30f, 0.65f, 1.00f, 0.35f))
62            plot_shaded_between("band", g_x, g_lo, g_hi)
63            next_line_style(float4(0.20f, 0.55f, 1.00f, 1.00f), 2.0f)
64            plot_line("mean", g_x, g_mid)
65        }
66        // A step series with the area under it filled.
67        plot(STAIRS, (title = "stairs + fill", size = float2(-1.0f, 300.0f),
68                      flags = ImPlotFlags.None)) {
69            setup_axes("bucket", "level")
70            setup_axes_limits(0.0lf, double(STEPS), 0.0lf, 5.0lf)
71            next_fill_style(float4(1.00f, 0.70f, 0.25f, 0.30f))
72            plot_shaded("fill", g_steps)
73            next_line_style(float4(1.00f, 0.55f, 0.10f, 1.00f), 2.0f)
74            plot_stairs("steps", g_steps)
75        }
76    }
77
78    harness_end_frame()
79}
80
81[export]
82def shutdown() {
83    if (g_ctx != null) {
84        DestroyContext(g_ctx)
85    }
86    harness_shutdown()
87}
88
89[export]
90def main() {
91    init()
92    while (!exit_requested()) {
93        update()
94    }
95    shutdown()
96}

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).